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

 

 

http://server.m.pp.cn/download/apk?appId=43449&ch_src=pp_uc_appdownload&ai=d3MAAwK5FsnWbTNxstYeHtQ%2B5cNoHvbOjNipNHTA35%2FQk8Yw%0D%0A&ut=d3MAA6j6x%2FY2fSZeYxnv9YLYabCtyCK4dkOTFw0JlEFX%2FyJd%0D%0A&uuid=d3MAAzfErcyJO%2FA4LFbgC3%2BfPL1cYsMR3gkdNxUfAy3zbQ2ww128xYgzogtFEUizeYAJDQaUNrRE%0D%0ABcyZuX5mLpJ18QY%3D%0D%0A&uc_param_str=frvecpmintnidnut

posted @ 2016-11-16 16:40  HuijunZhang  阅读(5573)  评论(0编辑  收藏  举报
中国