Public-key cryptography explained: hand out open padlocks, keep the only key
Public-key cryptography gives everyone two matching keys: a public one you can hand to the world and a private one you never share. Strangers can lock messages that only you can open, and you can sign things that anyone can check. Bitcoin uses the signing half.
Grandma Rosa wants Anna to send her a private note. But every message in the village goes through the square, where anyone can read it. A locked box would do it, except that Anna would need a copy of Rosa's key, and the key would have to travel through the square too.
So Rosa does something odd. She buys a dozen padlocks that all open with one key, and hands the open padlocks out to anyone who asks. Even the stranger at the gate takes one. Anna puts her note in a box, snaps one of Rosa's padlocks shut, and sends it across the square.
The stranger has a padlock of his own and nothing to open the box with. Anyone can lock. Only Rosa can unlock. That's public-key cryptography.
What it is
Public-key cryptography gives each person a matched pair of keys. The public key can be handed to anyone. The private key stays with its owner. What one key does, only the other can undo.
The idea was published by Whitfield Diffie and Martin Hellman in November 1976, in a paper that opens: "We stand today on the brink of a revolution in cryptography." Their key point: "The enciphering key E can thus be publicly disclosed without compromising the deciphering key D" (Diffie and Hellman, 1976).
Until then, both sides of a secret message needed the same key. Standard locks like AES still work that way: AES is "a symmetric block cipher" (NIST FIPS 197). Diffie and Hellman wanted to "minimize the necessity of secure key distribution channels and supply the equivalent of a written signature" (Diffie and Hellman, 1976). Padlocks for strangers, and signatures. Hold on to that second part.
How it works: a padlock made of two small numbers
A working recipe followed, from Ron Rivest, Adi Shamir and Leonard Adleman at MIT, in a technical memo dated April 1977 (MIT DSpace). It's known by their initials, RSA. Here's a toy version with numbers small enough to check on a calculator.
- Rosa picks two secret primes: 11 and 17. She multiplies them: 187.
- She makes the padlock. Her public key is the pair 187 and 3. Anyone can have it.
- She makes the key. From 11 and 17 she works out her private number: 107. You can only calculate it if you know the two primes.
- Anna locks a message. Her message is the number 42. She takes 42 to the power of 3 (the 3 from the padlock): 42 times 42 times 42 is 74,088. She divides by 187 and keeps the remainder: 36. She sends 36 across the square.
- Rosa unlocks it. She takes 36 to the power of 107 instead of 3, divides by 187 and keeps the remainder. Out comes 42.
- The snoop's problem. Anyone watching the square has 36, 187 and 3. To get 107, he needs the primes behind 187. For 187 that takes a minute. That's why the memo says "We recommend that n be about 200 digits long", and why "the security of the system rests in part on the difficulty of factoring the published divisor, n" (Rivest, Shamir and Adleman).
The padlock is easy to make from the key, and the key is practically impossible to make from the padlock. Every public-key system rests on a one-way step like that. RSA uses multiplying primes. Bitcoin uses a different one, on an elliptic curve, which gets its own article.
A small historical bonus: the same memo introduces its two users as "A and B (also known as Alice and Bob)" (Rivest, Shamir and Adleman). Our village went with Anna and Ben instead. Only one of them is honest.
Why it matters
Public-key cryptography made it possible to deal securely with strangers. You don't need to meet anyone first to swap a secret key.
Bitcoin uses the second half of the Diffie and Hellman wish: the signature. Nothing in the Bitcoin notebook is locked away. The white paper defines a coin "as a chain of digital signatures" (Nakamoto, 2008), and Bitcoin signs with "the Elliptic Curve Digital Signature Algorithm (ECDSA) with the secp256k1 curve" (Bitcoin developer guide). Your public key works like Rosa's padlock in reverse: everyone can use it to check that you signed, nobody can use it to sign for you.
Who gains: anyone who wants to receive money from a stranger without trusting them. Who pays: whoever loses the private key. With Rosa's padlocks, a lost key means a few unread notes. With Bitcoin, it means coins nobody can ever move again.
Where people get it wrong
- "My bitcoin is encrypted with my public key." It isn't encrypted at all. Your coins sit in a public record. The keys prove who may move them.
- "The public key is a weaker copy of the private key." It's a different thing calculated from it, like a padlock made to fit a key. Holding a padlock doesn't let you cut the key.
- "Anyone with my public key can open my box." A padlock only locks, and a public key only locks or checks. Opening and signing take the private key.
- "Bitcoin uses RSA." It doesn't. Bitcoin uses elliptic-curve keys: the same kind of one-way step, built on a curve instead of on multiplying primes.
Hand out padlocks, never keys
Look at what your wallet asks you to share and what it asks you to keep. Addresses and public keys are padlocks: hand them out freely. Private keys and recovery words are the key: they never leave your hands, not for a "verification", not for a "sync", not for anyone's support desk.
The stranger at the gate will sometimes ask for your key so he can "check your padlock works". Rosa has a simple answer for that, and so should you. A man who wants your key isn't testing the lock. He's moving in.
Frequently asked questions
What is public-key cryptography?
Public-key cryptography uses a pair of matching keys: a public key that can be shared with anyone and a private key that stays secret. Data locked with the public key can only be opened with the private key, and a signature made with the private key can be checked by anyone with the public key.
Who invented public-key cryptography?
Whitfield Diffie and Martin Hellman published the idea in their paper "New directions in cryptography" in November 1976. Ron Rivest, Adi Shamir and Leonard Adleman described a practical method, RSA, in an MIT technical memo in April 1977.
What is the difference between symmetric and public-key encryption?
In symmetric encryption, such as AES, the same secret key locks and unlocks the data, so both sides must share it beforehand. In public-key encryption, anyone can lock with the public key, but only the owner of the private key can unlock.
Does Bitcoin use public-key encryption?
Bitcoin uses public-key cryptography for digital signatures, not for hiding data. Every payment is signed with a private key using ECDSA on the secp256k1 curve, and anyone can check the signature against the public key. The transactions themselves are public.
Why can't someone work out the private key from the public key?
Because the public key is made with a one-way step: easy to calculate forwards, practically impossible to reverse with known methods on ordinary computers. RSA relies on the difficulty of splitting a very large number into its prime factors, and Bitcoin relies on a similar problem on an elliptic curve.
Sources
- Whitfield Diffie and Martin E. Hellman, New directions in cryptography, IEEE Transactions on Information Theory, November 1976
- R. L. Rivest, A. Shamir, L. Adleman, A method for obtaining digital signatures and public-key cryptosystems, MIT LCS technical memo MIT-LCS-TM-082 (April 1977), record
- R. L. Rivest, A. Shamir, L. Adleman, A method for obtaining digital signatures and public-key cryptosystems (full text)
- NIST, FIPS 197 Advanced Encryption Standard (AES), updated 9 May 2023
- Bitcoin developer guide, Transactions
- Satoshi Nakamoto, Bitcoin: A peer-to-peer electronic cash system (2008)

