算法模式:ECB(Electronic Code Book,电子密码本)模式
秘钥长度:128
补码方式:PKCS5Padding
解码串编码:十六进制
1 # aes加密算法padding : PKCS5 2 class AESUtils(): 3 def __init__(self): 4 self.__BLOCK_SIZE_16 = self.BLOCK_SIZE_16 = AES.block_size 5 self.key = '1234567812345678' 6 7 def encryt(self, str): 8 cipher = AES.new(self.key, AES.MODE_ECB) 9 x = self.__BLOCK_SIZE_16 - (len(str) % self.__BLOCK_SIZE_16) 10 if x != 0: 11 str = str + chr(x) * x 12 msg = cipher.encrypt(str) 13 msg = b2a_hex(msg).upper() 14 return msg 15 16 def decrypt(self, str): 17 cipher = AES.new(self.key, AES.MODE_ECB) 18 plain_text = cipher.decrypt(a2b_hex(str)) 19 return plain_text.rstrip('