Saturday 2 July 2016

How to encrypt and decrypt files using OpenPGP encryption




Some useful OpenPGP commands on linux.

Generating keys:
gpg2 --gen-key

Listing keys:
gpg2 --list-secret-keys

Exporting public key:
gpg --armor --export you@domain.com > mypublickey.asc
Or exporting to the public key to a key server:
gpg --keyserver search.keyserver.net --send-key you@domain.com

Exporting private key:
gpg2 --armor --export-secret-keys your_email@domain.com > myprivatekey.asc

Encrypting a file:
gpg2 --encrypt file.txt --output file.gpg

Importing the public key on the recipient PC:
gpg2 --import senderpublickey.asc

Decrypting a file:
gpg2 --output file.txt --decrypt file.gpg