1
$\begingroup$

For learning purposes, how to get the RSA's parameters (I use standard notation):

$n = p q $, where $p$ and $q$ are prime and $e$, $d$, such that $ed = 1 \ (mod\ \varphi (n)) $ when doing

ssh-keygen -t rsa -b 2048

i.e. how to get those parameters from the output:

----BEGIN PRIVATE KEY----
F2847XAPM...
...
----END PRIVATE KEY----

Note: this question is the reverse of What data is saved in RSA private key?: how to recover these parameters from the keys produced by ssh-keygen -t rsa -b 2048 (and not how to ask sshkeygen or openssl to output them from the start).

$\endgroup$
  • $\begingroup$ please check following answer crypto.stackexchange.com/questions/6593/… using openssl rsa -in Alice.key -text -inform PEM -noout $\endgroup$ – gusto2 Oct 31 '17 at 8:15
  • $\begingroup$ @gusto2 Very interesting, I'll look at this. Any idea for the reverse operation? How to go from ----PRIVATE KEY---- ... to these parameters? $\endgroup$ – Basj Oct 31 '17 at 9:11
  • $\begingroup$ "go from 'PRIVATE KEY' to parameters" means you want to read the PEM-format PRIVATE KEY file and output the fields in it? That's EXACTLY what openssl rsa -in file -text -noout does; -inform PEM is the default and not actually needed. -in means read from the file, and -text -noout means output the individual fields instead of a PEM blob. Assuming you mean thessh-keygen in OpenSSH, that actually writes PEM-format 'RSA PRIVATE KEY' which is a slightly different structure but contains the same key fields so openssl rsa can and does display the same for both. $\endgroup$ – dave_thompson_085 Nov 1 '17 at 1:02

Your Answer

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

Browse other questions tagged or ask your own question.