PyCrypto AES-CTR模式获得不同的输出

时间:2018-11-15 12:09:27

标签: python-3.x pycrypto

我使用PyCrypto加密我的数据,但是为什么它们的输出不同?

from Crypto.Cipher import AES
from Crypto.Util import Counter


data = b'\x02\x01\xf2\xca\x04\x03\x02P\x02\x02\x01\x80\xd0\x0f\x80\xd0\x0f'
key = b'random 16 string'
nonce = b'string 16 rand\x00\x01'
cipher = AES.new(key, AES.MODE_CTR, counter=lambda: nonce)
data_encrypted = cipher.encrypt(data)
print(data_encrypted)
# output is: b'_M\xed(\t4\xc4\x94\x80\x83K\x94qL\x15+R'

counter = Counter.new(2 * 8, prefix=b'string 16 rand', initial_value=1)
cipher = AES.new(key, AES.MODE_CTR, counter=counter)
data_encrypted = cipher.encrypt(data)
print(data_encrypted)
# output is: b'_M\xed(\t4\xc4\x94\x80\x83K\x94qL\x15+\xce'

这两种方法都会导致内存泄漏。如何使用pycryptodome达到效果

0 个答案:

没有答案