3

When I use GnuPG I can get a secret key saved as a file. Opening this file in a text editor I see that the key is encoded with base64. How do I find the actual prime number from the secret key? That is, how to I go from, say a 2048 bit, key to prime number?

I would like to see an algorithm that takes the file and gives the prime number.

I would also like to know how to make the secret key file given an actual prime number.

  • You could easily get the source code and take a look, GnuPG is open-source! – F. Hauri Mar 30 '13 at 6:48
5

You can use pgpdump to inspect public and private keys. The "Dump integers" option (pgpdump -i) will display the values used for the key. The values used for the private key (p,d,q,u) however will only be shown if the private key is not protected by a passphrase.

Since pgpdump only works with ascii-armored keys, you'll have to export your keys first.

3

First off, a secret key in GnuPG is unlikely to be one prime number. For RSA keys, public key contains two integers (n and e), while the private key contains four integers (d, p, q and u, in OpenPGP's terminology; p and q are primes and their product is equal to n). For ElGamal or DSA keys, the public key contains three or four integers (p, q, g, y) and the private key is one integer (x) which is not necessarily prime (primality of the private ElGamal key has no significance).

The actual format is described at length in the standard. If you implement some code to parse files as described in this standard, then you will get all the information you want. To speed up the effort (faster result, at the expense of less understanding -- implementing a protocol from scratch is a great way to learn it !), you may want to use some existing libraries which will do the parsing for you. For instance Bouncy Castle (in Java), or GnuPG (in C).

  • This is great. I will take a look at it. – Thomas Mar 30 '13 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.