Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

I hope that this question is not off topic here.

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 he prime number.

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

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

2 Answers 2

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).

share|improve this answer
    
This is great. I will take a look at it. –  Thomas Mar 30 '13 at 20:38

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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