加密不支持 python 3.x?
Crypto is not support python 3.x?
当我使用 python3.x 时,运行 代码:
with open('rsa_public_key.pem') as f:
key = f.read()
rsakey = RSA.importKey(key)
cipher = Cipher_pkcs1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(aes_key))
str1 = cipher_text
它会引发错误:
File "de_test.py", line 81, in get_login_data_inputPostString
cipher_text = base64.b64encode(cipher.encrypt(aes_key))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Crypto/Cipher/PKCS1_v1_5.py", line 137, in encrypt
em = b('\x00\x02') + ps + bchr(0x00) + message
TypeError: can't concat str to bytes
但是当我使用 python 2.6 时,它会通过。
所以不支持加密 python 3.x?
在没有看到 aes_key
的情况下,您似乎正在尝试传递 str
对象,而您应该将 bytes
对象传递给 encrypt()
。
当我使用 python3.x 时,运行 代码:
with open('rsa_public_key.pem') as f:
key = f.read()
rsakey = RSA.importKey(key)
cipher = Cipher_pkcs1_v1_5.new(rsakey)
cipher_text = base64.b64encode(cipher.encrypt(aes_key))
str1 = cipher_text
它会引发错误:
File "de_test.py", line 81, in get_login_data_inputPostString
cipher_text = base64.b64encode(cipher.encrypt(aes_key))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/Crypto/Cipher/PKCS1_v1_5.py", line 137, in encrypt
em = b('\x00\x02') + ps + bchr(0x00) + message
TypeError: can't concat str to bytes
但是当我使用 python 2.6 时,它会通过。
所以不支持加密 python 3.x?
在没有看到 aes_key
的情况下,您似乎正在尝试传递 str
对象,而您应该将 bytes
对象传递给 encrypt()
。