class AEScoder(): def __init__(self,encryptKey): self.__encryptKey = encryptKey self.aes = AES.new(str.encode(self.__encryptKey), AES.MODE_ECB) # 初始化加密器,本例采用ECB加密模式 def add_to_16(self,s): while len(s) % 16 != 0: s += '' return str.encode(s) # 返回bytes def encrypt(self, text): # AES加密 encrypted_text = str(base64.encodebytes(self.aes.encrypt(self.add_to_16(text))), encoding='utf8').replace('n', '') # 加密 return encrypted_text def decrypt(self, encrData): # AES解密 decrypted_text = str(self.aes.decrypt(base64.decodebytes(bytes(encrData, encoding='utf8'))).rstrip(b'').decode("utf8")) # 解密 return decrypted_textAEScoder(self.key).encrypt(code)
pythonaes加密
时间:2023-04-22
相关推荐