πŸ” Everything You Need to Know About PGP: Setup, Encryption, Decryption & Usage

What is PGP?

PGP security lock

PGP (Pretty Good Privacy) is a widely used encryption program that provides cryptographic privacy and authentication for data communication. It enables you to:

  • Encrypt messages and files
  • Verify authenticity through digital signatures
  • Ensure that only the intended recipient can read content

PGP uses a combination of symmetric and asymmetric encryption. It relies on public and private keys to encrypt and decrypt data securely. The most widely used open-source implementation is GnuPG (GPG).


πŸ”§ Installing GPG

On Linux (Debian/Ubuntu)

sudo apt update
sudo apt install gnupg

On macOS

brew install gnupg

On Windows

Download Gpg4win:
πŸ‘‰ https://gpg4win.org


πŸ›  How PGP Works (Quick Overview)

  • You generate a key pair (public & private)
  • You share your public key
  • Others encrypt messages using your public key
  • You decrypt using your private key

PGP

πŸ”‘ Generating a Key Pair

Run:

gpg --full-generate-key

Follow the prompts:

  1. Select key type (default RSA and RSA is fine)
  2. Choose key size β€” enter 4096
  3. Set an expiration date or 0 for no expiration
  4. Enter your name and email (or a placeholder like anon)
  5. Create a secure passphrase

To list your keys:

gpg --list-keys
gpg --list-secret-keys

πŸ“€ Exporting Your Public Key

Share your public key with others:

gpg --armor --export [email protected] > my_public_key.asc

This creates a text file you can send or upload.


πŸ“₯ Importing Someone’s Public Key

If you receive a key file:

gpg --import their_key.asc

Then verify:

gpg --list-keys

πŸ” Encrypting Files or Messages

Encrypt a File Using Public Key

gpg --encrypt --recipient KEYID file.txt

This creates file.txt.gpg, encrypted for the recipient.

Encrypt a Text Message

echo "Secret message" | gpg --encrypt --armor --recipient KEYID

πŸ”“ Decrypting Files or Messages

Decrypt a File

gpg --output decrypted.txt --decrypt file.txt.gpg

Decrypt an ASCII Message

gpg --decrypt

Paste your message, then press Ctrl+D (Linux/macOS) to finish.


πŸ”‘ Symmetric Encryption (No Key Pair Needed)

Encrypt with a Password

gpg --symmetric file.txt

Decrypt Symmetric File

gpg --output file.txt --decrypt file.txt.gpg

✍️ Signing Files and Messages

Sign a File

gpg --sign file.txt

Create a Readable Signed Message

gpg --clearsign message.txt

Verify a Signed Message

gpg --verify message.txt.asc

🧹 Deleting Keys

Delete a Secret (Private) Key

gpg --delete-secret-keys KEYID

Delete a Public Key

gpg --delete-key KEYID

To find KEYID:

gpg --list-keys

πŸ’Ύ Backing Up Keys

Export Public Key

gpg --armor --export KEYID > public.asc

Export Private Key

gpg --armor --export-secret-keys KEYID > private.asc

⚠️ Store your private key securely and offline.


πŸ›‘οΈ Best Practices

  • Use 4096 bit keys
  • Use a strong passphrase
  • Never share your private key
  • Always verify key fingerprints before using someone’s public key
  • Backup your private key and create a revocation certificate

πŸ–₯ GUI Options (Optional)


Examples

examples of PGP keys can be found here

https://tor.link

πŸ“Œ Summary

PGP is a powerful tool for encrypting files and messages, signing documents, and protecting digital communications. With GnuPG, it’s free and available across platforms. Once you understand how keys and encryption work, it becomes an essential part of any security-conscious workflow.