How to generate private and public keys using OpenSSL command

To generate private key, execute below command:

Step 1. Generate the private key:

openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048

Step 2: Generate the Public Key from the Private Key:

openssl rsa -pubout -in private_key.pem -out public_key.pem

Step 3: Convert the Private Key to Base64:

openssl base64 -A -in private_key.pem -out private_key_base64.txt

Step 4: Convert the Public Key to Base64:

openssl base64 -A -in public_key.pem -out public_key_base64.txt

The -A flag in the openssl base64 command ensures that the Base64 output is in a single line.

Leave a Comment

Scroll to Top