当前位置: 移动技术网 > IT编程>脚本编程>Python > python aes 加密

python aes 加密

2019年05月11日  | 移动技术网IT编程  | 我要评论

空白格 杨宗纬,君融贷,ci528

python 进行aes 加密报错,
windows pip install pycryptodome 安装crypto

linux pip install pycrypto

 1 import base64
 2 
 3 from crypto.cipher import aes
 4 
 5 
 6 def add_to_16(value):
 7     while len(value) % 16 != 0:
 8         value += '\0'
 9     return str.encode(value) 
10 
11 # 加密方法
12 def encrypt_oracle(self, text):
13     key = ''
14     aes = aes.new(self.add_to_16(key), aes.mode_ecb)
15     pad = lambda s: s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs)
16     encrypt_aes = aes.encrypt(self.add_to_16(pad(text)))
17     encrypted_text = str(base64.encodebytes(encrypt_aes), encoding='utf-8') 
18     return encrypted_text
19 
20 
21 # 解密方法
22 def decrypt_oralce(text):
23     key = ''
24     aes = aes.new(add_to_16(key), aes.mode_ecb)
25     base64_decrypted = base64.decodebytes(text.encode(encoding='utf-8'))
26     decrypted_text = str(aes.decrypt(base64_decrypted), encoding='utf-8').replace('\0', '')
27     return decrypted_text

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网