Cryptography Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.00

OpenSSL - Generating RSA Private and Public Keys

Part:   1  2 

This chapter describes:

  • What is RSA?
  • Generating RSA public and private keys.
  • Viewing Components of RSA Keys.
  • Encrypting RSA Keys.

What is RSA?

RSA is an asymmetric encryption algorithm developed in 1977 that use a pair of private key and public key. RSA is the initials of the developers of the RSA algorithm: Ron Rivest, Adi Shamir, and Leonard Adleman. Today, RSA is probably the most used the encryption algorithm for the Internet communication.

Generating RSA Key Pairs

Here is how to use OpenSSL to generate a pair of RSA private key and public key:

>openssl genrsa -out herong_rsa.key
Loading 'screen' into random state - done
Generating RSA private key, 512 bit long modulus
..++++++++++++
................++++++++++++
e is 65537 (0x10001)

>type herong_rsa.key
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBANoK3b+0NV1xrFLjsKFPLrxMReu3ezPxLjDWjktakq9gDGM5WUvI
CSENry/M1h2AhxGSxQluy4b1ynzBGWeO320CAwEAAQJAbQQn0NSKJflSvnLG+i/7
3vuHrg4j1FmOza5IoNZdJr9DyESMC+prebZkAFM2EW+ZLZy2JiEIqdDz79VAVRzs
ZQIhAPBvHYEWxCIcSYn8aG7o2lyY5/EB1gvwgAfSdWFlemUDAiEA6CijmKOX1WRd
KPf9g52Tpxk4TZzdjIpcbvYR7znIZs8CIBDxI3kXK5bju2LXwFwgWFKyC5X19Sk+
NydV8yN7zRYVAiEAni7CeUhONfmyeC2wsLL3Xg2TDV7qnc3QeVJ0mdl3MIUCIQCo
o0AdFXm789FfHuB+mVIKNtBLTAQNaMuXz6lXl7Ib7Q==
-----END RSA PRIVATE KEY-----

Note that:

  • The output says generating private key. But it is actually generating a pair of private key and public key.
  • The key pair is saved in an encoded format called PEM.

Viewing Components of RSA Keys

Here is how to see the components of a RSA key:

>openssl rsa -in herong_rsa.key -text
Private-Key: (512 bit)
modulus:
    00:da:0a:dd:bf:b4:35:5d:71:ac:52:e3:b0:a1:4f:
    2e:bc:4c:45:eb:b7:7b:33:f1:2e:30:d6:8e:4b:5a:
    92:af:60:0c:63:39:59:4b:c8:09:21:0d:af:2f:cc:
    d6:1d:80:87:11:92:c5:09:6e:cb:86:f5:ca:7c:c1:
    19:67:8e:df:6d
publicExponent: 65537 (0x10001)
privateExponent:
    6d:04:27:d0:d4:8a:25:f9:52:be:72:c6:fa:2f:fb:
    de:fb:87:ae:0e:23:d4:59:8e:cd:ae:48:a0:d6:5d:
    26:bf:43:c8:44:8c:0b:ea:6b:79:b6:64:00:53:36:
    11:6f:99:2d:9c:b6:26:21:08:a9:d0:f3:ef:d5:40:
    55:1c:ec:65
prime1:
    00:f0:6f:1d:81:16:c4:22:1c:49:89:fc:68:6e:e8:
    da:5c:98:e7:f1:01:d6:0b:f0:80:07:d2:75:61:65:
    7a:65:03
prime2:
    00:e8:28:a3:98:a3:97:d5:64:5d:28:f7:fd:83:9d:
    93:a7:19:38:4d:9c:dd:8c:8a:5c:6e:f6:11:ef:39:
    c8:66:cf
exponent1:
    10:f1:23:79:17:2b:96:e3:bb:62:d7:c0:5c:20:58:
    52:b2:0b:95:f5:f5:29:3e:37:27:55:f3:23:7b:cd:
    16:15
exponent2:
    00:9e:2e:c2:79:48:4e:35:f9:b2:78:2d:b0:b0:b2:
    f7:5e:0d:93:0d:5e:ea:9d:cd:d0:79:52:74:99:d9:
    77:30:85
coefficient:
    00:a8:a3:40:1d:15:79:bb:f3:d1:5f:1e:e0:7e:99:
    52:0a:36:d0:4b:4c:04:0d:68:cb:97:cf:a9:57:97:
    b2:1b:ed
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBANoK3b+0NV1xrFLjsKFPLrxMReu3ezPxLjDWjktakq9gDGM5WUvI
CSENry/M1h2AhxGSxQluy4b1ynzBGWeO320CAwEAAQJAbQQn0NSKJflSvnLG+i/7
3vuHrg4j1FmOza5IoNZdJr9DyESMC+prebZkAFM2EW+ZLZy2JiEIqdDz79VAVRzs
ZQIhAPBvHYEWxCIcSYn8aG7o2lyY5/EB1gvwgAfSdWFlemUDAiEA6CijmKOX1WRd
KPf9g52Tpxk4TZzdjIpcbvYR7znIZs8CIBDxI3kXK5bju2LXwFwgWFKyC5X19Sk+
NydV8yN7zRYVAiEAni7CeUhONfmyeC2wsLL3Xg2TDV7qnc3QeVJ0mdl3MIUCIQCo
o0AdFXm789FfHuB+mVIKNtBLTAQNaMuXz6lXl7Ib7Q==
-----END RSA PRIVATE KEY-----

(Continued on next part...)

Part:   1  2 

Dr. Herong Yang, updated in 2007
Cryptography Tutorials - Herong's Tutorial Notes - OpenSSL - Generating RSA Private and Public Keys