Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 591
Steven Avatar asked Jun 15 '11 01:06

Steven


People also ask

Can RSA public key be derived from private key?

The public key is derived from the private key at generation time, and with the private key at any point in the future it is possible to re-derive the public key easily. It is not feasible to go the other way. Given a public key it is not easy to derive the private key.

How do I generate my public key?

To generate an SSH private/public key pair for your use, you can use the ssh-keygen command-line utility. You can run the ssh-keygen command from the command line to generate an SSH private/public key pair. If you are using Windows, by default you may not have access to the ssh-keygen command.


2 Answers

Depends on the algorithm. With RSA, you cannot, with EC you can. However, the public key is usually always stored together with the private key (not the other way around, though, of course), so this is not really a problem (if you have the private key, the same file also includes the public key).

like image 198
Thilo Avatar answered Oct 06 '22 05:10

Thilo


Extracting public RSA key from a private key from the command line

Command line comparison to show there is no difference between a public RSA key and an extracted key if you ignore whitespace.

  1. Generate public private key pairing under home directory with no passphrase and no coment.

    ssh-keygen -t rsa -f ~/id_rsa -N '' -C ""

  2. Generate public key into file 'extracted_public_key'

    ssh-keygen -y -f '/home/vagrant/id_rsa' > extracted_public_key

  3. Diff public key with 'extracted_public_key' file ignoring white space.

    diff -b id_rsa.pub extracted_public_key

Ignoring whitespace at the end of id_rsa.pub there is no difference between a public key and an extracted key.

like image 22
notapatch Avatar answered Oct 06 '22 04:10

notapatch