Wednesday, September 9, 2015

How to encrypt and decrypt files Using GPG ?

If not redirected, please click here

GPG uses public key cryptography for encryption and decryption. You would first need to generate a public private key-pair. If you want to send an encrypted document to someone, you need to encrypt the document using the recipient's public key and send it to her.

How to encrypt a file using GPG ?

You can send a document to a recipient encrypting it with the recipient's public key.

# gpg –armor --output output.asc --encrypt --recipient <recepient-user-id> file.txt

Here, the document file.txt will be encrypted using the recipient's pubic key and the ASCII-armored output will be saved in output.asc.

If the user sends output.asc to the recipient, no one else can decrypt the document other than the recipient. 

How to decrypt an encrypted file using GPG ?

The recipient can retrieve the original document using her private key.

# gpg –output file.txt –decrypt output.asc



How to encrypt a file using GPG symmetric key ?

You can also use symmetric cipher to encrypt the document using a different passphrase (other than that of your private key).

# gpg –armor –output output.asc –symmetric file.txt

How to decrypt a file encrypted using a GPG symmetric key ?

While decrypting the document, use the following command with the same passphrase that you used while encrypting it.

# gpg –output file.txt -d output.asc

This will decrypt and extract the original file to file.txt.

Hope this helps.

No comments:

Post a Comment