I have a C# application that uses following public keys to encrypt and decrypt (using corresponding private key) successfully. I am using the same Public Key in Python to encrypt, using following code. I am getting following error:
module 'Crypto.PublicKey.RSA' has no attribute 'import_key'
I referred RSA - pycryptodome.readthedocs.io to check 'import_key'. It says extern_key (string or byte string)
.
Note: I have pycrypto 2.6.1
installed. Verified using conda list
.
How to fix this so that Python can use the same key that was successfully used by C# application?
Python Code
import Crypto
from Crypto.PublicKey import RSA
pubkey = 'BgIAAACkAABSU0ExAAQAAAEAAQB5ad3IFUIQ+NJeJEVlHJb0BaXhPCpeP+477ql+2dsNLzpn+3f2Lm5UWZhig60rx7/5/rAlAH+emU6WwOZNxtMtFbdu9CNBUjRp9FiEmJHZLaGqqmEFDyp287k3HVCFVzxxRAEy8ftL/q6KaE3KKrHoFiMozretUXulYy5OE1yR7w=='
import base64
decodedPublicKey = base64.b64decode(pubkey)
pub_key = RSA.import_key(decodedPublicKey)
encrypted = pub_key.encrypt('hello world', None)
print(encrypted)
text = pvt_key.decrypt(encrypted)
print(text)