PGP Encryption
PGP encryption secures message and file contents so only intended recipients can read them. This chapter covers practical encryption and decryption patterns with both CLI and GUI workflows.
Basic Encryption Concepts
PGP uses a hybrid encryption system that combines:
- Public-key (asymmetric) encryption: Uses recipient's public key to encrypt data
- Symmetric encryption: Uses a randomly generated session key for the actual file encryption
- Digital signatures: Ensures authenticity and integrity of the message
Pre-Encryption Checklist
Before encrypting sensitive data:
- Verify recipient fingerprint out-of-band.
- Confirm recipient key is not expired/revoked.
- Confirm you selected the correct recipient key ID.
- Decide whether to sign + encrypt (recommended for most sensitive workflows).
Encrypting Files
Command Line (GPG)
To encrypt a file for a specific recipient:
# Encrypt a file for a specific recipient
gpg --encrypt --recipient recipient@email.com document.txt
# This creates an encrypted file: document.txt.gpg
To encrypt and sign a file (recommended):
# Encrypt and sign a file
gpg --encrypt --sign --recipient recipient@email.com document.txt
To encrypt for multiple recipients:
gpg --encrypt --sign \
--recipient alice@example.com \
--recipient bob@example.com \
document.txt
Using GUI Applications
Kleopatra/GPG4Win:
- Right-click the file in Explorer
- Select "Sign and Encrypt"
- Choose recipient(s)
- Complete the encryption process
GPG Suite (macOS):
- Right-click the file in Finder
- Select "Services" → "OpenPGP: Encrypt File"
- Choose recipient(s)
Decrypting Files
Command Line Decryption
# Decrypt a file
gpg --decrypt encrypted-file.gpg > decrypted-file.txt
# If the file is signed, GPG will verify the signature automatically
If signature verification fails, do not trust the decrypted content until the key and message integrity are validated.
GUI Decryption Applications
Kleopatra/GPG4Win:
- Double-click the .gpg file
- Enter your passphrase when prompted
GPG Suite (macOS):
- Double-click the encrypted file
- Enter your passphrase when prompted
Text Encryption
To encrypt text messages (e.g., for secure messaging):
# Create a text file with your message
echo "Secret message" > message.txt
# Encrypt the message
gpg --encrypt --armor --recipient recipient@email.com message.txt
# The output file (message.txt.asc) contains ASCII-armored encrypted text
# that can be copied and pasted into emails or messaging apps
For interactive terminal use:
# Encrypt text from stdin
echo "Secret message" | gpg --armor --encrypt --recipient recipient@email.com
Verifying Signatures
To verify a signed file:
# Verify a signature
gpg --verify document.txt.sig document.txt
Expected outcomes:
- Good signature from trusted key: accept.
- Good signature from unknown/untrusted key: verify fingerprint before trust.
- Bad signature: treat as tampering or wrong key.
Best Practices
- Always verify signatures when decrypting files from others
- Use trusted channels for initially exchanging public keys
- Sign your encrypted messages to provide authentication
- Keep your private key secure and protected by a strong passphrase
- Use ASCII armor (
--armorflag) when sharing encrypted text via text channels
Common Encryption Errors
Encrypted to Wrong Recipient
- Symptom: intended recipient cannot decrypt.
- Fix: check recipient key ID/fingerprint before encrypting.
Untrusted Signature Warning
- Symptom: signature validates cryptographically but trust is low.
- Fix: verify fingerprint and set trust deliberately.
Corrupted Armored Block
- Symptom: decryption fails after copy/paste.
- Fix: send as attached
.asc/.gpgfile instead of inline paste.
Next Steps
- Email Integration - Configure email clients for PGP
- Best Practices - Advanced security considerations