28
$\begingroup$

What data is saved in RSA private key in openssl? How to view it?

Wikpedia says these variables are saved.

$\endgroup$
6
  • 1
    $\begingroup$ I'm not sure I understand the question. Perhaps you could elaborate a bit. What are you trying to accomplish? Why do you want to know? How will you use the answer? Some information on those sorts of topics might increase the odds that we can offer an answer that will be useful to you. $\endgroup$
    – D.W.
    Mar 6, 2013 at 5:11
  • 1
    $\begingroup$ How to view it will greatly depend on how the private key is encoded. That said, I have often had success reading the private key certificate into Java and then accessing the info from there. $\endgroup$
    – mikeazo
    Mar 7, 2013 at 14:49
  • $\begingroup$ Are you talking about openssl compatible key? Can you give the code? $\endgroup$ Mar 7, 2013 at 18:17
  • $\begingroup$ To view the details of an RSA key or certificate, use the following command: openssl rsa -in key.pem -text –noout $\endgroup$ Oct 29, 2017 at 22:45
  • $\begingroup$ This is already mentioned in the accepted answer. $\endgroup$ Oct 30, 2017 at 9:45

1 Answer 1

43
$\begingroup$

You can print the data with (change PEM to DER if required):

openssl rsa -in Alice.key -text -inform PEM -noout

The following data is stored:

  • Modulus ($n = pq$)
  • Public exponent ($e$)
  • Private exponent ($d = e^{-1} \pmod{\phi{(n)}}$)
  • First prime ($p$)
  • Second prime ($q$)
  • First exponent, used for Chinese remainder theorem ($d_P = d \pmod{p - 1}$)
  • Second exponent, used for CRT ($d_Q = d \pmod{q - 1}$)
  • Coefficient, used for CRT ($q_{\mathrm{inv}} = q^{-1} \pmod{p}$)
$\endgroup$
2
  • 2
    $\begingroup$ That works :) Somehow I haven't got a notification or haven't noticed it. Why is all this data saved? Is it not enough to save just p, q, e and probably d? What are first and second exponent used for? Is there any integrity check performed to verify that these variables are consistent? $\endgroup$ Apr 26, 2013 at 19:55
  • $\begingroup$ The "extra" info is probably saved for performance reasons. We wouldn't want to recompute things over and over for potentially lots of uses of the key. $\endgroup$
    – Chris H.
    Oct 7, 2020 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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