我在python中加密文件:
from Crypto.Cipher import AES
from Crypto import Random
key = Random.new().read(16)
iv = Random.new().read(AES.block_size)
encryptor = AES.new(key, AES.MODE_CBC, iv)
with open(in_file, 'rb') as fin, open(out_file, 'wb') as fout:
fout.write(iv)
while True:
chunk = fin.read(16*1024)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += b' ' * (16 - len(chunk) % 16)
fout.write(encryptor.encrypt(chunk)
print base64.b32encode(key)
但是当我尝试用openssl解密它之后:
openssl aes-256-cbc -d -in enc -out new.zip
它返回魔术袋号码
我做错了什么?
答案 0 :(得分:0)
程序使用128位AES密钥进行加密,如下所示:
key = Random.new().read(16)
所以,而不是使用
openssl aes-256-cbc -d -in enc -out new.zip
使用此
openssl aes-128-cbc -d -in enc -out new.zip