How it works · 9 of 34 Core
How does public-key cryptography work?
A padlock anyone can close
Public-key cryptography: Public-key cryptography gives each person two linked keys: a public one anyone can use to lock a message, and a private one only its owner holds to unlock it; strangers can send secrets without ever sharing a key first.
Loading the animation…
Say it like this Public-key cryptography gives everyone a padlock anyone can close but only its owner can open, so strangers can share a secret without ever meeting first.
Under the hood — for builders
- Real example: a padlock in numbers
- RSA, the first public-key padlock (1977), with primes small enough to check by hand. The padlock is two public numbers; the key is a third number that only the owner can work out:
- Why the hard part stays hard
- Splitting n is easy at 4 digits and impractical at 617 (RSA-2048). The record so far, drawn to scale by digits:
- Bigger keys for the same safety
- Public keys need far more bits than code-wheel keys to be equally hard to break. Same strength, key length drawn to scale:
- Why it only carries the key
- Padlocks are slow. So the padlock carries one short key, and the code wheel (B1) scrambles everything after. Time for one operation:
- What https really does
- TLS 1.3 (RFC 8446) agrees the key instead: each side mixes its own secret with the other's public half (Diffie–Hellman).
- Same promise
- No shared secret beforehand, and a listener who sees every public number still can't compute the key.
- Typical sizes
- RSA 2048 bits minimum (3072 for 128-bit strength); elliptic curves P-256 or X25519, 256 bits.
- Measure it
- Click the padlock in a browser: certificate key type and size, and TLS 1.3 under connection details.
- Watch out
- Whoever copies the private key opens every padlock. Keep it in a hardware store, never in a config file.
- History
- Diffie & Hellman 1976; RSA 1977. GCHQ's Ellis and Cocks found it first (1970–73), kept secret until 1997.
- Sources
- Diffie & Hellman, New Directions in Cryptography (1976) · Rivest, Shamir & Adleman (CACM 1978) · NIST SP 800-57 Pt 1 Rev. 5 · RFC 8446 · RSA-250 factorisation announcement (Feb 2020).
What happens in the public-key cryptography animation, step by step?
- The bank gives away open padlocks to anyone who asks: its public key. It keeps one key that opens them all: its private key.
- You've never met the bank and share no secret with it. You just take a padlock.
- Your turn: drag your box, with a fresh code-wheel key inside, onto the padlock. Snap. Now not even you can open it.
- A listener on the road took a padlock too. It doesn't help: closing is easy, opening needs the bank's key.
- Only the bank can open it. Now both of you hold the same code-wheel key, and the rest of the visit is scrambled with it. Every https visit starts like this.
- But who says this stall is really the bank? A fake stall can hand out padlocks too. Next: proving who wrote something.
What everyday example explains public-key cryptography?
A stall handing out open padlocks for free. Anyone can take one and snap it shut on a box; only the stall owner's single key opens any of them. Copying the padlock doesn't help you open it.
Why should a team care about public-key cryptography?
When a vendor says "encrypted in transit", check what happens to the private key: whoever holds it can open every padlock, so it should sit in a protected store (D&C E4), never in a config file.