OpenSSL "rsa -pubout" - Extract RSA Public Key

Q

How to extract the public key from an RSA key file using OpenSSL "rsa" command?

✍: FYIcenter.com

A

If you want to extract the public key out from an RSA key file (private key an public key), you can use the OpenSSL "rsa -pubout" command as shown below:

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

OpenSSL> rsa -in my_rsa.key -pubout -out my_rsa_pub.key
writing RSA key

OpenSSL> exit

C:\Users\fyicenter>type my_rsa_pub.key
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx1SQU1GfsBNB6XU2nqrw
IHm1ImXPAcsInQNfhFcpzpku3Kmm0LpDZF1oqkqLNLlh0qVIIlfuMNnVNLAozbUb
aJalFUdSGPAVl7jFRZxpDai+d4U2we14MO3kTwy7H3ZeRKzWklL2FCeKo2c20gzF
OfxdePwSx9lBT7efFNc5NHRPdPbP/e1Zx1VqB8wAKTgRwafQmFfYUbbk2Cc5ftZ8
yhWc43+2qWzhWm6Ig8knbapPLMPw6bFzwD+ck+6d7zbCG++NrBuXH858iDJfzLgr
wic7fW0cRiF+yBpiTmAw6G9HH0CQu8HNBgMfXZIuYjZER4MObmqSGiRTyN9mEFtS
WwIDAQAB
-----END PUBLIC KEY-----

Options used in this command are:

  • "-in my_rsa.key" - Read the RSA key file from: C:\Users\fyicenter\my_rsa.key
  • "-pubout" - Extract the public key out of the RSA key file
  • "-out my_rsa_pub.key" - Save the public key in a file with no password protection.

 

OpenSSL "rsa -pubin" - View RSA Public Key

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

OpenSSL "genrsa" and "rsa" Commands

⇑⇑ OpenSSL Tutorials

2017-02-03, 1031👍, 0💬