

This includes the modulus (also referred to as public key and n), public exponent (also referred to as e and exponent default value is 0x010001), private exponent, and primes used to create keys (prime1, also called p, and prime2, also called q), a few other variables used to perform RSA operations faster, and the Base64 PEM encoded version of all that data. Viewing the key elements Įxecute command: " openssl rsa -text -in private_key.pem"Īll parts of private_key.pem are printed to the screen. So this command doesn't actually do any cryptographic calculation - it merely copies the public key bytes out of the file and writes the Base64 PEM encoded version of those bytes into the output public key file. However, OpenSSL has already pre-calculated the public key and stored it in the private key file.

It is relatively easy to do some cryptographic calculations to calculate the public key from the prime1 and prime2 values in the public key file. $ openssl rsa -pubout -in private_key.pem -out public_key.pemĪ new file is created, public_key.pem, with the public key. Make sure to prevent other users from reading your key by executing chmod go-r private_key.pem afterward.Įxtracting the public key from an RSA keypair Įxecute command: " openssl rsa -pubout -in private_key.pem -out public_key.pem" $ openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048 Generate an RSA keypair with a 2048 bit private key Įxecute command: "openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048" (previously “openssl genrsa -out private_key.pem 2048”) 2 Extracting the public key from an RSA keypair.1 Generate an RSA keypair with a 2048 bit private key.
