Skip to main content

Creating a Key Pair

Generating an RSA key pair is essential for encrypting and decrypting sensitive data securely. This guide provides step-by-step instructions for generating an RSA key pair using the command line.

Generating an RSA Key Pair on the Command Line

Using OpenSSL

OpenSSL is a widely-used toolkit for the TLS and SSL protocols. It can also be used to generate RSA key pairs.

Steps

  1. Generate the Private Key:

    openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
  2. Extract the Public Key:

    openssl rsa -pubout -in private_key.pem -out public_key.pem
  3. View the Private Key:

    cat private_key.pem
  4. View the Public Key:

    cat public_key.pem