How to load a public RSA key into Python-RSA from a file?
To load an OpenSSL generated public key file with python-rsa library, try
with open('public_key.pub', mode='rb') as public_file:
key_data = public_file.read()
public_key = rsa.PublicKey.load_pkcs1_openssl_pem(key_data)
If on Python3, You also need to open the key in binary mode, e.g:
with open('private_key.pem', 'rb') as privatefile:
Python-RSA uses the PEM RSAPublicKey format and the PEM RSAPublicKey format uses the header and footer lines: openssl NOTES
-----BEGIN RSA PUBLIC KEY-----
-----END RSA PUBLIC KEY-----
Output the public part of a private key in RSAPublicKey format: openssl EXAMPLES
openssl rsa -in key.pem -RSAPublicKey_out -out pubkey.pem