OpenSSL "pkey -text" - Print RSA Key in Text

Q

How to print private key contents in text format using OpenSSL "pkey" command?

✍: FYIcenter.com

A

If you want to see contents of a private key in text format, you can use the OpenSSL "pkey -text" command as shown below:

C:\Users\fyicenter>\local\openssl\openssl.exe

OpenSSL> pkey -in my_rsa.key -text -noout
Private-Key: (1024 bit)
modulus:
    00:c0:13:13:00:63:be:36:61:60:40:9e:ff:b7:35:
    30:08:f9:c5:11:95:04:2c:b3:32:6d:58:ef:ad:cf:
    6c:2b:ca:87:b4:5d:b0:f7:c7:4b:66:e6:d0:72:3a:
    37:19:ec:76:e9:ed:09:5a:51:17:f6:5e:69:37:68:
    dd:36:50:23:90:18:f1:bc:1b:8b:88:70:af:b6:bc:
    27:08:76:24:c2:c0:bd:83:ba:39:31:62:0e:6e:e6:
    00:2d:81:00:93:ac:d0:6a:26:21:a7:18:31:28:34:
    96:b1:02:f4:7f:3e:4a:85:33:c0:f6:be:fa:1a:b7:
    a8:b1:8a:c8:5a:ff:ad:f5:51
publicExponent: 65537 (0x10001)
privateExponent:
    42:b9:9d:9d:42:09:3f:3c:fe:c2:14:3a:43:7c:0f:
    ae:de:8e:0e:78:95:15:ae:3e:f3:6b:b4:ff:cd:92:
    07:78:79:42:38:56:15:0d:bf:ed:04:7c:1f:62:87:
    e7:d2:94:d0:d9:0e:a9:b8:88:39:87:3c:c8:09:fe:
    e7:32:59:d7:c7:b5:6f:4f:fb:9a:0a:76:e9:00:0d:
    6b:f4:e3:91:63:24:ca:77:f8:cf:f8:80:8b:05:fb:
    92:99:bd:ca:2c:c4:d8:b1:95:61:45:21:ca:7c:77:
    f4:67:c3:e1:49:63:fc:7e:a0:5d:27:12:a1:d1:8d:
    d1:c4:26:fa:03:be:74:c1
prime1:
    00:f0:08:9f:1f:ae:71:cb:e8:c4:f2:ce:f1:b4:f1:
    dd:ec:ed:74:1d:a7:b9:02:72:5a:aa:34:cb:30:20:
    4d:81:d0:a5:23:87:0b:65:00:55:d6:d1:4e:4f:48:
    11:55:eb:b0:06:89:d9:05:0c:eb:15:75:25:d0:a0:
    1f:52:44:4b:59
prime2:
    00:cc:d9:c9:74:c6:68:89:15:36:0d:24:8b:71:eb:
    97:21:d8:b3:74:a2:ec:0d:40:15:48:dd:6c:b6:a2:
    0c:80:2c:bd:e3:3e:1d:26:7d:52:41:ad:7e:24:25:
    c4:37:5b:e0:72:a3:b4:8a:b1:01:ef:3a:ab:ce:bf:
    9a:44:99:52:b9
exponent1:
    66:e1:ab:22:6f:28:c3:57:7f:a2:fa:e4:4a:c4:28:
    74:f6:ca:00:33:f5:6e:81:09:2f:4e:f5:90:29:28:
    4f:6d:d8:7a:43:d5:b4:72:d2:58:02:da:67:cc:e1:
    f1:4b:d5:e4:d7:8c:b7:47:74:33:7c:44:bb:09:06:
    a3:c2:35:f1
exponent2:
    46:d1:03:53:db:43:48:20:8d:0e:fe:13:36:ce:ba:
    f0:78:79:91:58:c1:41:d3:65:88:4b:03:ca:1f:3b:
    33:14:44:90:ca:68:49:66:09:89:aa:f0:70:8e:9d:
    c6:85:7c:92:25:05:c4:ec:6c:3e:c7:89:9d:6f:9f:
    65:17:9c:01
coefficient:
    00:ea:49:fe:27:6c:18:37:fd:fa:5a:50:ac:85:f0:
    a7:a7:cd:46:d4:7e:ab:fd:ce:2d:48:37:5f:4d:70:
    36:ab:b8:37:07:80:fd:76:89:b7:fb:43:48:22:b8:
    8f:f6:a5:5d:2b:31:fd:3f:30:57:c1:d0:69:92:06:
    c6:05:7d:4d:53

This test tells us that an RSA key (private key and public key pair) is made of:

modulus, also called n: The modulus part of the private key and the public key
publicExponent, also called e: The exponent part of the public key
privateExponent, also called d: The exponent part of the private key
prime1, also called p: The first prime number
prime2, also called q: The second prime number
coefficient, also called qInv (Inverse of q): qInv * q  mod p = 1
exponent1, also called dp: d mod (p-1)
exponent2, also called dq: d mod (q-1)

Options used in this command are:

  • "-in my_rsa.key" - Read the private key file
  • "-text" - Print out key information in text format.
  • "-noout" - Do not include the key itself in the output.

 

OpenSSL "genpkey" Command for RSA Keys

⇒⇒OpenSSL Tutorials

2018-01-16, 460👍, 0💬