Use RSA private key to generate public key?

c2h2 picture c2h2 · Mar 9, 2011 · Viewed 528.8k times · Source

I don't really understand this one:

according to: http://www.madboa.com/geek/openssl/#key-rsa , You can generate a public key from a private key.

openssl genrsa -out mykey.pem 1024
openssl rsa -in mykey.pem -pubout > mykey.pub

My initial thinking was that they are generated in a pair together. Does RSA private key contain the sum? or the public key?

Answer

Raam picture Raam · Mar 9, 2011
openssl genrsa -out mykey.pem 1024

will actually produce a public - private key pair. The pair is stored in the generated mykey.pem file.

openssl rsa -in mykey.pem -pubout > mykey.pub

will extract the public key and print that out. Here is a link to a page that describes this better.

EDIT: Check the examples section here. To just output the public part of a private key:

openssl rsa -in key.pem -pubout -out pubkey.pem

To get a usable public key for SSH purposes, use ssh-keygen:

ssh-keygen -y -f key.pem > key.pub