首页 > 编程语言 > 详细

python aes 加密

时间:2019-05-10 18:59:41      阅读:189      评论:0      收藏:0      [点我收藏+]

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

 

python aes 加密

原文:https://www.cnblogs.com/yubs/p/10846045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!