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去驗證