$ cd ../writing
2026-04-21·5 min read·
#security#pgp#cryptography#encryption

How PGP actually works

From key generation to encrypted email — no history lesson, just the mechanics.

Most explanations of PGP start with history. This one doesn't.

Here's what actually happens when you encrypt an email.

$ The two key problem

PGP gives you two mathematically linked keys:
Private key → only you have this, never share it
Public key → share with everyone, post it everywhere

The math works like this:
What the PUBLIC key locks → only the PRIVATE key can unlock
What the PRIVATE key signs → the PUBLIC key can verify

They are a matched pair. Generated together. Linked by math that is
easy in one direction and nearly impossible to reverse.

$ Generating your keys

gpg --gen-key

GPG asks for your name and email, then generates your key pair.
Under the hood it uses ed25519 — modern elliptic curve cryptography.
A 256-bit key gives you equivalent or better security than a 4096-bit RSA key.

Your keys end up here:
~/.gnupg/
├── pubring.kbx ← public keyring
├── private-keys-v1.d/ ← your private key (encrypted with your passphrase)
└── openpgp-revocs.d/
└── YOURFINGERPRINT.rev ← revocation certificate

$ What is a fingerprint

Your public key is a long blob of text — hundreds of characters.
The fingerprint is a short SHA-1 hash of that blob:
Public key (long) → SHA-1 → 0BDF7EBFB38BF69D9531F7E6CD44CE2DA84B5813

It's a short unique ID people use to verify they downloaded
the correct key for you. Like a passport number for your key.

$ Putting your key on a keyserver

A keyserver is a public directory of PGP keys — like a phonebook:
Name: JobinAj
Email: [email protected]
Public key: [blob of text]
Fingerprint: 0BDF7E...B5813

Upload your key so anyone can find it:

gpg --keyserver keys.openpgp.org \
    --send-keys YOUR_FINGERPRINT

Anyone can now look up your email and get your public key
without you having to send it to them manually.

$ How encrypted email actually works

Someone wants to send you a secret message:

# Step 1 — they find your public key
gpg --keyserver keys.openpgp.org \
    --recv-keys 0BDF7EBFB38BF69D9531F7E6CD44CE2DA84B5813

Step 2 — they write their message

echo "Here is a secret vulnerability I found" > message.txt

Step 3 — they encrypt it with YOUR public key

gpg --encrypt --armor \ --recipient [email protected] message.txt

The encrypted output looks like this:
-----BEGIN PGP MESSAGE-----
hQIMA8g3X2kZmxP0ARAAxK3p...
completely unreadable gibberish
-----END PGP MESSAGE-----

They email you that block of text.

# Step 4 — you decrypt it with YOUR private key
gpg --decrypt message.txt.asc

Your private key unlocks it. Nobody else can — not Gmail,
not your ISP, not anyone who intercepted it in transit.

$ Signing — proving it's really you

Encryption hides content. Signing proves identity.

# Sign a message
gpg --sign --armor message.txt

Verify a signature

gpg --verify message.txt.asc

If verification passes — the message came from that person
and was not tampered with in transit.

If it fails — something changed after it was signed.

$ The revocation certificate

When GPG generated your keys it also created this:
~/.gnupg/openpgp-revocs.d/YOURFINGERPRINT.rev

If your private key is ever stolen or lost, you publish this
certificate to tell the world the key is no longer valid.
Back it up somewhere that is not your laptop.

$ Why this matters

Normal email:
You → Gmail → Internet → Their server → Them
↑ ↑
Google reads anyone who
everything intercepts it

PGP encrypted email:
You → [locked box] → Internet → [locked box] → Them
↑
only their private key
can open this

The security comes from one mathematical property — it is easy
to multiply large numbers together but nearly impossible to
factor the result back into the original numbers.
Your privacy lives in that asymmetry.

-- null

newer →Simulating failure on AWS EKS — what the observability pipeline caught