0
工作,我有一個簡單的Python腳本M2Crypto並不像OpenSSL,以便進行AES-128 CBC
import binascii
import M2Crypto
data = 'my super secret text to encrypt'
print 'secret data: ', data
key = '\0' * 16
iv = key
key_iv_as_hex = binascii.b2a_hex(key)
print 'hex representation of key/iv: ', key_iv_as_hex
ENC = 1 # means we are encrypting
cipher_enc = M2Crypto.EVP.Cipher(alg='aes_128_cbc', key=key, iv=iv, op=ENC)
v1 = cipher_enc.update(data)
v1 = v1 + cipher_enc.final()
encrypted_data_as_base64 = binascii.b2a_base64(v1)
print 'encrypted base64 data: ', encrypted_data_as_base64
結果是:
secret data: my super secret text to encrypt
hex representation of key/iv: 00000000000000000000000000000000
encrypted base64 data: SorHWZBvmWq0cH1QRmsoGo/nYzukotB/Jheg20AKk/w=
當我使用OpenSSL的命令行加密相同的字符串在Python小號
echo 'my super secret text to encrypt' >> in.txt
openssl enc -aes-128-cbc -e -in in.txt -out out.txt -a -K 00000000000000000000000000000000 -iv 00000000000000000000000000000000
cat out.txt
SorHWZBvmWq0cH1QRmsoGkPiuRPIkAGD4BHv3Hu1X7/nO9pH2TulXHRZ7gFgEDFn
爲什麼my super secret text to encrypt
成爲SorHWZBvmWq0cH1QRmsoGo/nYzukotB/Jheg20AKk/w=
:工具,我得到不同的加密數據當openssl命令行工具被使用時,cript變成SorHWZBvmWq0cH1QRmsoGkPiuRPIkAGD4BHv3Hu1X7/nO9pH2TulXHRZ7gFgEDFn
?我也無法解碼python腳本中由openssl編碼的數據。
我該怎麼做?
-nosalt沒有幫助。 – Zelid