Diagramium
🗝️ Narrated diagram

Public key cryptography, explained

Two keys instead of one: how strangers agree on a secret over a wire everyone can read, how signatures prove who wrote something, and why the maths refuses to run backwards.

16 steps3 min readNarrated with a studio voice
Public key cryptography, explainedhow do we share a key?the answer: two keysone to give awayone to keep forever⚠ safe to publishAlice fetches itciphertextarrives untouchedthe only key that opens itthe same maths, reversedsign a short digestanyone can checkwhy it cannot be forgeda smaller trapdoorused with fast ciphersthe finished messageA source or sink outside the system (person or system)Alice has a secret to sendA transform that changes data1The old key problemA transform that changes data2One pair of keysWhere data rests — a file, table or databaseThe public keyWhere data rests — a file, table or databaseThe private keyWhere data rests — a file, table or databasePublished for anyoneA transform that changes data3Lock with the public keyA transform that changes data4Across the open wireA transform that changes data5Open with the private keyA transform that changes data6Signing, in reverseA transform that changes data7Sign a fingerprintA transform that changes data8Anyone can verifyA transform that changes data9The trapdoorA transform that changes data10Elliptic curvesA transform that changes data11Hybrid, in practiceA source or sink outside the system (person or system)Bob reads it and trusts it
Public key cryptography, explained — the complete diagram. Press Present to watch it build itself.
Step 1 of 16

Alice has a secret to send

Alice wants to send Bob a message nobody else can read. They have never met, they share no secret, and everything between them is a public wire owned by strangers. For almost all of history that was simply impossible.

Step 2 of 16

The old key problem

The old way needed a shared key delivered in advance by a trusted courier. That works fine for two people. For a thousand people who all need to talk to each other you would need four hundred and ninety nine thousand five hundred separate keys, every one hand carried.

Step 3 of 16

One pair of keys

In nineteen seventy six Whitfield Diffie and Martin Hellman published the idea that keys could come in pairs: two enormous numbers bound together, so that whatever one of them locks, only the other can unlock. British code breakers had quietly found the same trick years earlier and told nobody until the nineteen nineties.

Step 4 of 16

The public key

One of the pair is the public key. You publish it, print it, hand it to your worst enemy. That is genuinely safe, because knowing this number gives nobody a practical route back to its twin, and the whole system depends on that one fact.

Step 5 of 16

The private key

The other is the private key, and it should never leave your machine. Modern phones and laptops keep it inside a dedicated security chip that will happily perform operations with it but refuses to read it back out, so even malware on the device cannot copy it away.

Step 6 of 16

Published for anyone

Publishing a key is easy; publishing it as yourself is the hard part. Alice needs Bob's real key, not an impostor's, so a certificate authority signs a statement binding that key to that name. Almost every remaining problem in this field is the identity problem wearing a hat.

Step 7 of 16

Lock with the public key

Alice encrypts using Bob's public key. The strange part is that she immediately loses the ability to undo her own work. The message is now sealed in a box that only Bob's private key opens, and Alice does not have one.

Step 8 of 16

Across the open wire

The result crosses the open internet, through routers and cables belonging to companies neither of them has heard of. Anyone may copy every byte. Without the private key those bytes are indistinguishable from noise, and copying them buys an attacker nothing at all.

Step 9 of 16

Open with the private key

Bob applies his private key and the original text falls out. No secret was ever transmitted, no courier travelled, no meeting took place. That is the entire trick, and it sits underneath every padlock icon you have ever glanced at.

Step 10 of 16

Signing, in reverse

Now run the machine the other way. Alice applies her own private key to a message, and anyone holding her public key can check the result. It hides nothing, since everybody can read it, but only the holder of that private key could have produced it. That is a signature.

Step 11 of 16

Sign a fingerprint

In practice you never sign a whole document. You run it through a hash function to get a short fingerprint, thirty two bytes for the common one, and sign that instead. Change a single comma anywhere in the file and the fingerprint changes completely, so the signature no longer fits.

Step 12 of 16

Anyone can verify

Verification is public and cheap. Software updates, code packages and every secure website work this way. You do not have to trust the wire at all; you only have to check that the signature matches a key you already decided to trust.

Step 13 of 16

The trapdoor

So why can nobody derive the private key? Because some operations are easy forwards and brutal backwards. Multiplying two three hundred digit primes takes a fraction of a second. Splitting the answer back into those primes would keep every computer on Earth busy for longer than the universe has existed.

Step 14 of 16

Elliptic curves

Elliptic curves give the same one way trapdoor using far smaller numbers. A curve key of two hundred and fifty six bits is about as strong as a three thousand bit factoring key, which is why phones and messaging apps almost all prefer them now.

Step 15 of 16

Hybrid, in practice

Public key maths is slow, so nothing uses it for bulk data. Your browser uses it once, for a few milliseconds, to agree on a single fast shared key, and everything after that is ordinary symmetric encryption running at gigabytes per second on hardware built for it.

Step 16 of 16

Bob reads it and trusts it

So Bob reads a message only he could open, carrying a signature only Alice could have made, over a network that watched every byte and learned nothing at all. That quiet arrangement is what makes the modern internet usable in the first place.

Watch it explain itself

Every step above is narrated aloud. Play it, or open it in the editor and make it yours — no account needed.