OpenSSL "genpkey -algorithm rsa" - Generate RSA Key

Q

How to generate a new RSA private key using OpenSSL "genpkey" command?

✍: FYIcenter.com

A

If you need a new RSA private key in order to create a new certificate, you can use the OpenSSL "genpkey" command as shown below:

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

OpenSSL> genpkey -algorithm rsa -out my_rsa.key
.................++++++
.++++++

OpenSSL> exit

C:\Users\fyicenter>type type my_rsa.key
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMATEwBjvjZhYECe
/7c1MAj5xRGVBCyzMm1Y763PbCvKh7RdsPfHS2bm0HI6NxnsduntCVpRF/ZeaTdo
3TZQI5AY8bwbi4hwr7a8Jwh2JMLAvYO6OTFiDm7mAC2BAJOs0GomIacYMSg0lrEC
9H8+SoUzwPa++hq3qLGKyFr/rfVRAgMBAAECgYBCuZ2dQgk/PP7CFDpDfA+u3o4O
eJUVrj7za7T/zZIHeHlCOFYVDb/tBHwfYofn0pTQ2Q6puIg5hzzICf7nMlnXx7Vv
T/uaCnbpAA1r9OORYyTKd/jP+ICLBfuSmb3KLMTYsZVhRSHKfHf0Z8PhSWP8fqBd
JxKh0Y3RxCb6A750wQJBAPAInx+uccvoxPLO8bTx3eztdB2nuQJyWqo0yzAgTYHQ
pSOHC2UAVdbRTk9IEVXrsAaJ2QUM6xV1JdCgH1JES1kCQQDM2cl0xmiJFTYNJItx
65ch2LN0ouwNQBVI3Wy2ogyALL3jPh0mfVJBrX4kJcQ3W+Byo7SKsQHvOqvOv5pE
mVK5AkBm4asibyjDV3+i+uRKxCh09soAM/VugQkvTvWQKShPbdh6Q9W0ctJYAtpn
zOHxS9Xk14y3R3QzfES7CQajwjXxAkBG0QNT20NIII0O/hM2zrrweHmRWMFB02WI
SwPKHzszFESQymhJZgmJqvBwjp3GhXySJQXE7Gw+x4mdb59lF5wBAkEA6kn+J2wY
N/36WlCshfCnp81G1H6r/c4tSDdfTXA2q7g3B4D9dom3+0NIIriP9qVdKzH9PzBX
wdBpkgbGBX1NUw==
-----END PRIVATE KEY-----

Note that the output is labeled as private key. But it actually contains two parts, a private key and a matching public key, as a key pair for encryption and decryption.

Also note that the output is not password protected, which is not recommended. Private keys must be kept private with a password.

 

OpenSSL "genpkey" Command for RSA Keys

⇒⇒OpenSSL Tutorials

2018-01-27, 755👍, 0💬