openSSL: how to extract public key? – Stack Overflow

The following command generates a file which contains both public and private key:

openssl genrsa -des3 -out privkey.pem 2048 

Source: here

With OpenSSL, the private key contains the public key information as well, so a public key doesn’t need to be generated separately

How can we extract the public key from the privkey.pem file?


share|improve this question
add comment

2 Answers

openssl rsa -in privkey.pem -pubout > 

That writes the public key to

share|improve this answer
Thanks a lot !! –  Jake Apr 22 ’12 at 19:23
You’re welcome 🙂 –  stewe Apr 22 ’12 at 19:28

add comment

For those interested in the details – you can see what’s inside the public key file (generated as explained above), by doing this:-

openssl rsa -noout -text -inform PEM -in -pubin 

or for the private key file, this:-

openssl rsa -noout -text -in key.private 

which outputs as text on the console the actual components of the key (modulus, exponents, primes, …)


Leave a Reply

Your email address will not be published. Required fields are marked *