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

I am creating an encryption strategy for a laboratory project and want to know if it is possible to create a public key only from a private key?

Otherwise, can the public key be created simultaneously with the private key from any key generator?

PS Fast google really didn't help.

+7
source share
4 answers

Private and public keys are created together. In addition, the standard storage format for the RSA private key includes all fields of the public key, as it is useful for optimized implementations and masking (protection against some side attacks). See RSA Standard: PKCS # 1 .

Edit: the question has been edited; it was originally RSA-only. Another asymmetric algorithm does not require the public key to be obtained from the private key, and there are no requirements to the contrary. For discrete logarithm-based algorithms (Diffie-Hellman, El-Gamal, DSA, and elliptic curve variants of all of these), the public key is easily calculated from the private key. One can imagine a degenerate RSA, in which knowledge of the private key does not allow to recover the public key, but for this it is not necessary to store several key elements that are necessary for good performance (fully remembering the coefficients of the RSA module allows for 4x speed increase through the Chinese remainder theorem, therefore, all save the factors). On a more conceptual basis, the public key is, well, public, so it is assumed that "everyone" knows this; from a practical point of view, the private key storage format almost always includes provisions for storing the public key, as well as at least sufficient data to recover the public key.

+10
source

Yes, you can do this (for some, maybe not all, pkc schemes). From the ssh-keygen man file:

-y Read the private key file and print the public key.

+7
source

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

+2
source

Retrieving the RSA public key from the private key from the command line

A command line comparison to show that there is no difference between the RSA public key and the extracted key if you ignore the spaces.

  • Generate a batch of the public secret key in the home directory without a passphrase and without a comment.

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

  • Create public key in file 'extract_public_key'

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

  • Public key with file 'extract_public_key' ignoring the space.

    diff -b id_rsa.pub extracted_public_key

Ignoring spaces at the end of id_rsa.pub does not differ between the public key and the extracted key.

0
source

All Articles