aes加密
算法模式: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('\0')
算法模式:ECB(Electronic Code Book,电子密码本)模式
秘钥长度:128
补码方式:PKCS5Padding
解码串编码:base64
1 class AESUtil: 2 __BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size 3 4 @staticmethod 5 def encryt(str, key): 6 cipher = AES.new(key, AES.MODE_ECB) 7 x = AESUtil.__BLOCK_SIZE_16 - (len(str) % AESUtil.__BLOCK_SIZE_16) 8 if x != 0: 9 str = str + chr(x) * x 10 msg = cipher.encrypt(str) 11 msg = base64.urlsafe_b64encode(msg).replace('=', '') 12 return msg 13 14 @staticmethod 15 def decrypt(enStr, key): 16 cipher = AES.new(key, AES.MODE_ECB) 17 enStr += (len(enStr) % 4) * "=" 18 decryptByts = base64.urlsafe_b64decode(enStr) 19 msg = cipher.decrypt(decryptByts) 20 paddingLen = ord(msg[len(msg) - 1]) 21 return msg[0:-paddingLen]
附在线加密解密:http://www.seacha.com/tools/aes.html
转载请注明:http://www.cnblogs.com/zhjsll/p/6070172.html
作者:无言
如果您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】
如果您希望与我交流互动,欢迎微博互粉
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。