Reputation: 55
I am trying to decrypt a message in hexadecimal format using a private key which is also in hexadecimal format with Python and the pycrypto module included. Everytime I write the last line of code,"rsakey..." I get the error "binAscii.Error:Incorrect padding". I know this works using pycrypto and not M2Crypto because a colleague already succeded in decrypting the message. What am I missing? I forgot to mention that I entered "-----BEGIN RSA PRIVATE KEY----" at the beginning and END at the end of the key.
from Crypto.PublicKey import RSA
key = open("/path/to/key", "r").read()
rsakey = RSA.importKey(key)
Upvotes: 0
Views: 2553
Reputation: 93978
-----BEGIN RSA PRIVATE KEY----
is for PEM encoded (also known as ASCII armored) keys. Those keys should be PKCS#8 or #12 DER encoded private keys, then encoded to base 64 and surrounded by the start and ending lines (as you described).
Just putting -----BEGIN RSA PRIVATE KEY----
and -----END RSA PRIVATE KEY----
around the data won't cut it.
Upvotes: 1