[pycrypto] extract RSA public from X509 certificate file
dolfandringa at gmail.com
Fri Aug 19 10:55:02 CST 2011
I am playing around with PyCrypto and public key encryption using RSA.
The thing is that I already have an RSA private key, and an X509 certificate
which contains the RSA public key belonging to the private key.
I succesfully exported the public key starting with the private key file
from Crypto.PublicKey import RSA
from Crypto import Random
When I compare the print output with the output of the openssl tool which
can extrac the public key from an x509 certificate file with the following
openssl x509 -inform pem -in /path/to/certificate.crt -pubkey -noout
The public keys are indeed the same, so the exporting with pycrypto and
extracting with openssl produce the same public key.
But is it possible to use pycrypto (or another library) to extract the
public key from the certificate file (like openssl does)?
Another question is the following:
This works fine:
But this raises a typeError:
But the keys are symmetric right? So it should be possible to encrypt
something with the private key and decypt that with the public key. It
doesn't make sense to do this since then anyone can decrypt the data, which
you just encrypted with the private key, making encryption useless in the
first place. But the difference between RSA public and private keys is only
the name. Which one is public, and which one is private is just a matter of
choice, not a technical difference right? So why then does the PyCrypto
library raise a TypeError in the first case?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the pycrypto