aes加密

算法模式:ECB(Electronic Code Book,電子密碼本)模式html

祕鑰長度:128算法

補碼方式:PKCS5Paddingapp

解碼串編碼:十六進制ui

 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加密

補碼方式:PKCS5Paddingurl

解碼串編碼:base64spa

 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.htmlcode

轉載請註明:http://www.cnblogs.com/zhjsll/p/6070172.htmlserver

 

 

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

相關文章
相關標籤/搜索