提前准备好字典,一行一个,自行修改偏移vi和key
import base64
from Crypto.Cipher import AES
def AES_Encrypt(key, data):
vi = '7B579877ECB01812'
pad = lambda s: s + (16 - len(s) % 16) * chr(0)
data = pad(data)
cipher = AES.new(key.encode('utf8'), AES.MODE_CBC, vi.encode('utf8'))
encryptedbytes = cipher.encrypt(data.encode('utf8'))
encodestrs = base64.b64encode(encryptedbytes)
enctext = encodestrs.decode('utf8')
return enctext
key = '7BAB2440978E8950'
#需要加密的字典路径
data = open('/root/passwd3.txt','r')
line = data.readlines()
for lines in line:
AES_Encrypt(key, lines)
enctext = AES_Encrypt(key, lines)
#保存结果的路径
AES1 = open('/root/AES.txt', 'a')
AES1.write(enctext+'\n')
AES1.close()
结果如下: