Though she be but little, she is fierce!

Encrypting and Decrypting a file using GPG key pair

GNU Privacy Guard (GPG) is a tool to provide encryption and signing services for transferring data securely. This post is about generating a public-private key pair for encrypting and decrypting a message. GPG generates a public key of the size preferred by you for a given email id, and a pass-phrase which is the private key.

Generating the Key pair

It is very simple to generate a key pair in GPG. Follow the instructions

This file will contain the public key. If you want to get the Public key in ascii, give

gpg --armor --export priya1111@gmail.com > priya1111-pub-asc.gpg

Importing Public Key

gpg --import priya1111@gmail.com <filename>

Encrypting a file

Consider you want to encrypt the file sun.txt and send it to Priya
Give the command as follows

$ gpg --recipient priya_key --armor --encrypt sun.txt

Here priya-key contains the public key of priya1111@gmail.com. The above commands generates a file
sun.txt.asc which is the encrypted file. You can send this file through gmail securely as it
is in the encrypted format

Decrypting a file

You can decrypt the file with your private key.

gpg --decrypt sun.txt.asc > sun.txt

You will get the decrypted file.

There are ways to add signature to your file using the public key. You can even add photo ID as a part of the signature. You can refer the following link if interested.click here