Here I am going to Introduce Asymmetric encryption decryption technology with an example lab in Redhat Enterprise Linux.

So I will show you how to create Private key and how to create Public Key.Also we will learn how to encrypt a file using Publick Key

and How to Decrypt it using Private key. So Basically We use Public Key for Encryption and Private key For Decryption.We will also learn how to password protect the Private key and how to remove the password from private key.I have used openssl command line tool to perform all this private key public key encryption decryption Lab.

#### Step 1:How to create a Private key?

**here I am showing you how to create a 1024 bit Private key using RSA key. You can also create a Private Key using DSA Algorithm but here I am**

**using RSA Algorithm.**

[root@one cryptography]# openssl genrsa -out private.pem 1024 Generating RSA private key, 1024 bit long modulus ........................++++++ ...................++++++ e is 65537 (0x10001) [root@one cryptography]#

#### Step 2: Now Using Private key I am going to create Public Key.

**here I am going to create a Public key with the help of Private key i have created above.**

[root@one cryptography]# openssl rsa -in private.pem -out publick.pem -outform PEM -pubout

#### Step 3:Now create a File

**I am going to create afile to test encryption decryption of the file through Private and Public key generated above.**

[root@one cryptography]# echo " ethical hacking Tuition center" > satish.txt

**using above command i have created a text file named satish.txt you can verify it using below command.**

[root@one cryptography]# ls private.pem publick.pem satish.txt

#### Step 4: How to encrypt File using Public Key

**see carefully I am going to encrypt the file satish.txt with Public Key.**

[root@one cryptography]# openssl rsautl -encrypt -inkey publick.pem -pubin -in satish.txt -out encryption.bat

#### Step 5:Now Delete the satish.txt file

**When we have encrypted File now we use to delete the simple text file which is not encrypted or which is not secure.**

[root@one cryptography]# ls encryption.bat private.pem publick.pem satish.txt [root@one cryptography]# rm -rf satish.txt [root@one cryptography]# ls encryption.bat private.pem publick.pem [root@one cryptography]#

#### Step 6: Now how to Decrypt the File using Private Key

###### Now I am going to decrypt the encrypted file named encryption.bat with the help of Private key.If you don’t have Private key you can’t decrypt the File.

[root@one cryptography]# openssl rsautl -decrypt -inkey private.pem -in encryption.bat -out hacking.txt

##### Now you can see I have decrypted encryption.bat to hacking.txt.

[root@one cryptography]# ls

encryption.bat hacking.txt private.pem publick.pem

[root@one cryptography]#

##### you can also check or verify the content of the decrypted text.

[root@one cryptography]# cat hacking.txt ethical hacking Tuition center [root@one cryptography]#

#### How to Encrypt Private RSA key with a PASSPHRASE.

[root@one cryptography]# openssl genrsa -des3 -out private.pem 1024 Generating RSA private key, 1024 bit long modulus ...++++++ ....++++++ e is 65537 (0x10001) Enter pass phrase for private.pem: Verifying - Enter pass phrase for private.pem: [root@one cryptography]#

#### How to remove the passphrase from Private key

[root@one cryptography]# openssl rsa -in private.pem -out newprivate.pem Enter pass phrase for private.pem: writing RSA key

#### Now Check the output:

root@one cryptography]# ls encryption.bat hacking.txt newprivate.pem private.pem publick.pem [root@one cryptography]#

###### This is a snapshot for you guys.

If you have any doubt or suggestion regarding Public key or Private key generation or usage you can ask me or suggest me through comment section.

I will try to enhance my article and also update if required.