when I use python3.x , run code:
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
it will raise an error:
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
But when I use python 2.6 , it will pass.
so crypto is not support python 3.x?
Without seeing the aes_key
, it looks like you're trying to pass a str
object where you should be passing a bytes
object to encrypt()
.