一、代码
from Crypto.Cipher import AESimport 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 msgstr="my name is maple" #此处的key的长度需要16位key="ffm1111111111111"res=encryt(str,key)print(res)pres=decrypt(res,key)print(pres)