Reputation: 93
from Crypto.PublicKey import RSA
pub_key = """
-----BEGIN PGP PUBLIC KEY BLOCK-----
mykeyhere
-----END PGP PUBLIC KEY BLOCK-----
"""
public_key_object = RSA.importKey(pub_key)
This throws the following error - RSA key format is not supported
This is a public PGP key generated with RSA-4096 encryption. I am curious why this library could be throwing errors. Could there be invalid characters in the key? Doesn't look like there are any , no forward slashes or whatnot.
Upvotes: 2
Views: 2645
Reputation: 958
try python-gnupg. it takes care of everything for you
pycryptodome is a low level library. we are free to pick and choose the type of key and cipher over there but we use it only if we know what we are doing ^_^
Upvotes: 0
Reputation: 93948
For PGP you need a PGP specific library. PGP, at least for the public keys, uses it's own defined format. If you look at your cryptographic library then you will find this nugget:
The following formats are supported for an RSA public key:
So the PGP key format is not supported, only X.509 keys (the certificate contains the subject public key which contains a PKCS#1 public key if RSA is used, like a Matrushka doll) and OpenSSH keys.
Here is the first library that I found: py-pgp, which includes:
from pgp import read_key
key = read_key(data)
for "transferable" keys, which I presume are public keys.
Upvotes: 1