How to Create a Public/Private Key Pair?
Public/private key pairs are the cryptographic tool that allows you to encrypt and decrypt data. A public key can be shared with anyone without worry, but a private key should never be given out without protection.
In Private key encryption, the same key (secret key) is used for encryption and decryption. In this key is symmetric because the only key is copied or shared by another party to decrypt the cipher text. It is faster than public-key cryptography.
In a Public key, two keys are used, one key is used for encryption and another key is used for decryption. One key (public key) is used to encrypt the plain text to convert it into cipher text and another key (private key) is used by the receiver to decrypt the cipher text to read the message.
The article focuses on creating public/private key pairs using OpenSSL.
OpenSSL
OpenSSL is a cryptography software library or toolkit that makes communication over computer networks more secure. The OpenSSL program is a command-line tool for using the various cryptography functions of OpenSSLâs crypto library from the shell. It is generally used for Transport Layer Security(TSL) or Secure Socket Layer(SSL) protocols. OpenSSL is licensed under an apache-style license, which means that under some simple license conditions, one can use the toolkit for commercial or non-commercial purposes.
- Download OpenSSLâs required libraries from here.
- Run the .exe file and install OpenSSL in the system.
- Open the command prompt (cmd) and redirect the path to the bin folder.
Steps to Create Public/ Private Key Pair
Step 1: Creating a Private Key
Type command openssl, hit enter and then use the following command to create private key:
genrsa -out myprivatekey.pem
This command generates 512 bit long private key and stores it into a file having .pem extension
Output:
Step 2: Create Public Key
Type command openssl, hit enter and then use the following command to create public key:
rsa -in myprivatekey.pem -pubout -out mypublickey.pem
This command will create the public key for the private key created in the previous step.
Output:
Contact Us