from Crypto.Cipher import AES加密解密
Posted angelyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了from Crypto.Cipher import AES加密解密相关的知识,希望对你有一定的参考价值。
一、代码
from Crypto.Cipher import AES import base64 """ AES加密算法 """ #加密 def encryt(str, key): BS = AES.block_size pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) cipher = AES.new(key, AES.MODE_ECB,str) msg = cipher.encrypt(pad(str)) msg = base64.encodestring(msg) return msg #解密 def decrypt(enStr, key): unpad = lambda s: s[0:-ord(s[-1])] cipher = AES.new(key, AES.MODE_ECB) decryptByts = base64.decodestring(enStr) msg = cipher.decrypt(decryptByts) msg=unpad(msg.decode()) return msg str="my name is maple" key="ffm1111111111111" res=encryt(str,key) print(res) pres=decrypt(res,key) print(pres)
以上是关于from Crypto.Cipher import AES加密解密的主要内容,如果未能解决你的问题,请参考以下文章
from Crypto.Cipher import AES找不到模块报错的解决方案记录
from Crypto.Cipher import AES找不到模块报错的解决方案记录
python3 安装Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto.Cipher'