Created
August 14, 2018 20:00
-
-
Save svenmuennich/b080220b3595ab1e3c2de115a04fd6cb to your computer and use it in GitHub Desktop.
How to create a public and private key pair for RSA encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Generate a new RSA key pair (public and private key) with a 4096 bit long modulus. | |
# You can optionally pass e.g. '-aes256' to encrypt the key pair with a passphrase. The key | |
# pair will be saved as 'private.pem' ('pem' is just a container file format, | |
# see https://serverfault.com/questions/9708/what-is-a-pem-file-and-how-does-it-differ-from-other-openssl-generated-key-file). | |
openssl genrsa -out private.pem 4096 | |
# 2. Extract the public key from the RSA key pair ('private.pem'). | |
# The result is again saved in a 'pem' file, this time named 'public.pem'. | |
openssl rsa -in private.pem -outform PEM -pubout -out public.pem | |
# 3. Verify the contents of the two files | |
# private.pem: should start with '-----BEGIN RSA PRIVATE KEY-----' in its first line | |
head private.pem | |
# public.pem: should start with '-----BEGIN PUBLIC KEY-----' in its first line | |
head public.pem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment