cmd执行命令:pip install pycryptodome
1 # -*- coding: utf-8 -*- 2 # __author__ = 'Carry' 3 4 import base64 5 from Crypto.Cipher import AES 6 7 8 # str不是16的倍数那就补足为16的倍数 9 def add_to_16(value): 10 while len(value) % 16 != 0: 11 value += '\0' 12 return str.encode(value) # 返回bytes 13 14 key = '123456' # 密码 15 text = 'adadadffdbfhgjhgj' # 待加密文本 16 aes = AES.new(add_to_16(key), AES.MODE_ECB) # 初始化加密器 17 encrypted_text = str(base64.encodebytes(aes.encrypt(add_to_16(text))), encoding='utf-8').replace('\n', '') # 执行加密并转码返回bytes 18 print(encrypted_text)
执行完:
C:\Python36\python3.exe E:/study/py/py3_stu/2018-01-31/c.py
goUqddXOjbPejrOP+GtLvCWFke5JclH9fd6JrgCQE7w=
Process finished with exit code 0
到这个链接http://tool.chacuo.net/cryptaes去验证