Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

May sound stupid to many, but I would like to have some pointers on what exactly is contained inside a private key. I have decent understanding of public/private keys/certificates (have created them many times) and their purpose but would like to take a step back and see what is inside them using a "dump" utility or something - Would I be able to see big prime numbers etc contained inside the private key?

Is there a utility to show me the "logical content" of the output of the following command as opposed to a bunch of ASCII characters?

openssl genrsa

generates

-----BEGIN RSA PRIVATE KEY-----
MIIBPAIBAAJBANdINmZY7VuoRy5VZYwnVIAE/0sd/HkaDVXfMNpwVeKo7K2XLC6U
jpnPFP2MaDEqxs0T6cKVMmt5FsNGyfdKbvcCAwEAAQJBAMGuPQrtPHY2uftsZtSl
2bbnSAr7qlYFYzP7fYc4g3xLWSc5viAe7KgsU7+jXNCqEvflf4iOxhCadUK07APG
…
-----END RSA PRIVATE KEY-----

Any pointers appreciated. Same question also applies to the public key btw..

share|improve this question
    
Try the pkey option. –  rath Dec 16 '13 at 23:16
    
thx rath for the pointer. The following command worked for me. . . openssl rsa -in privkey.pem -text –  user1813603 Dec 16 '13 at 23:37
4  
Good to know. May I suggest that you write an answer showing how the RSA key components get displayed? –  rath Dec 16 '13 at 23:59
3  
This question appears to be off-topic because it is about using openssl and the format it uses, rather than about the cryptographic keys themselves. It would be on-topic on Unix & Linux. –  Gilles Dec 19 '13 at 19:24
add comment

1 Answer

$ openssl genrsa | openssl rsa -text -noout
Private-Key: (512 bit)
modulus:
    00:e7:be:c0:b7:7a:8a:e6:58:c3:dc:3e:eb:ed:bc:
    a7:15:04:78:8d:9d:fe:a2:83:aa:ca:85:5f:4b:ae:
    5c:fa:3d:bd:2b:a9:91:58:e1:da:d8:8a:bd:25:6d:
    07:10:74:52:2f:ee:ce:bd:3c:c6:89:01:2e:ff:9a:
    3b:61:4d:e7:81
publicExponent: 65537 (0x10001)
privateExponent:
    00:8d:b9:23:44:51:e5:c6:0e:fc:e0:a1:7e:49:2a:
    79:07:aa:6f:4b:34:17:38:2d:cb:72:04:f4:8d:64:
    f9:a9:72:94:30:6e:d8:65:81:e7:be:05:a8:19:fb:
    82:c9:77:b2:fa:76:0d:4b:ff:b3:ad:a9:f1:9e:55:
    cd:b3:d2:c8:41
prime1:
    00:fc:ea:3f:dd:a9:5f:6f:4d:05:41:50:04:81:8e:
    c7:6b:a0:95:d3:d4:36:09:73:b4:b8:06:db:fc:f2:
    89:0c:e9
prime2:
    00:ea:92:65:f9:06:58:11:f4:bc:fe:e6:10:0b:80:
    51:73:18:1b:91:24:27:83:ab:c9:b3:4c:79:01:1f:
    60:86:d9
exponent1:
    00:e6:7b:63:30:51:c5:d2:dc:51:c9:af:6e:2b:d3:
    3e:10:eb:0b:1f:3b:e8:f2:bc:2b:18:f9:c7:48:c0:
    8d:fc:e1
exponent2:
    11:b3:04:30:bb:12:d0:20:08:56:af:63:4c:8a:dd:
    1a:73:1a:39:64:61:fa:e4:6e:6e:b1:f9:7b:65:33:
    b2:59
coefficient:
    3a:6d:f6:8f:4b:d2:c3:a8:53:aa:32:0d:b9:c5:50:
    d8:db:9c:e3:9b:a8:40:c3:c0:14:2b:7e:67:25:67:
    b7:03

The numbers are in hexadecimal with a funny format, except for the public exponents. You can convert them to your favorite format with a bit of text processing.

Python is a nicer environment for playing with common cryptographic primitives such as RSA. Install pycrypto in addition to the core Python distribution.

~% python                    
Python 2.7.3 (default, Apr 10 2013, 06:20:15) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.PublicKey import RSA
>>> k = RSA.generate(1024)
>>> k.n
137989966843141497713268840304515414544555471898207567571275317377632553064486587462119814017348007187827660662823764767983835450392238729966453378972206066751517751868783987379434607487796692691455662440665457077710749398149038850219502976135918708465391309679715881739357423413344802810741483299360557935787L
>>> k.p * k.q
137989966843141497713268840304515414544555471898207567571275317377632553064486587462119814017348007187827660662823764767983835450392238729966453378972206066751517751868783987379434607487796692691455662440665457077710749398149038850219502976135918708465391309679715881739357423413344802810741483299360557935787L
>>> (k.d * k.e) % ((k.p - 1) * (k.q - 1))
1L
share|improve this answer
add comment

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.