前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python aes 加密

python aes 加密

作者头像
py3study
发布2020-01-16 14:55:57
1.5K0
发布2020-01-16 14:55:57
举报
文章被收录于专栏:python3python3

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

linux pip install pycrypto

代码语言:javascript
复制
 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
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-06-04 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档