我正在尝试将一些代码从python2更新到3,并且在使用特定的加密功能时遇到了一些问题。这是python 2代码:
trans_raw = '6c9474469ddf7578f3e5ad8a4c703d99'
raw_prime = '583423bbbf900e9a211664861e28c9f347835017'
transkey = trans_raw.decode('hex')
prime = raw_prime.decode('hex')[:16]
r = rijndael.rijndael(transkey)
result = r.encrypt(prime).encode('hex')
print result
#result = fa016bdda2f884d9126fc746f5a00714
此功能中使用的rijndael来自:https://github.com/sectroyer/SmartCrypto/blob/master/PySmartCrypto/rijndael.py
我已经尝试将其转换为python3,但我不觉得即时消息即将到来。 这就是我尝试过的
trans_raw = '6c9474469ddf7578f3e5ad8a4c703d99'
raw_prime = '583423bbbf900e9a211664861e28c9f347835017'
transkey = binascii.unhexlify(trans_raw)
prime = binascii.unhexlify(raw_prime)[:16]
r = AES.new(transkey, AES.MODE_ECB)
ciphertext = r.encrypt(prime)
result = binascii.hexlify(ciphertext).decode('utf-8')
print(result)
#result = ba5a2b6bb7176dd321250e7d672b0a4a
我尝试使用https://gist.github.com/jeetsukumaran/1291836#gistcomment-901601 评论中的某人说已针对python 3更新了。我也曾尝试使用内置的python AES.new(transkey,AES.MODE_ECB),但这些选项均未返回任何与我正在寻找的选项相似的值。有人知道我在想什么吗?