RSA - Can you create a public key from a private key?

Viewed 13696

I am creating an encryption strategy for a lab project and want to know if there exists the capability to create a public key from just the private key?

Otherwise, can the public key only be created at the same time as the private key from some key generator?

P.S. A quick google didnt really help.

5 Answers

Actually the public key is mostly generated with the private key together.

If you lost your public key but got the private key, you can still recover the public key from the private key.

All you have to do is to extract the public key from the private key like below:

Extracting the public key from the private key:

ssh-keygen -f~/.ssh/test_rsa -y > ~/.ssh/test_rsa.pub

-f option specifies the file of the key to list the fingerprint for -y option will read a private SSH key file and prints an SSH public key to stdout. The public key part is redirected to the file with the same name as the private key but with the .pub file extension.

NOTE: If the key has a password set, the password will be required to generate the public key.

Related