Public-key cryptography: how it works
The open padlock as a metaphor, encryption with the public key, signing with the private key and hybrid cryptography.
The padlock metaphor
Imagine handing out open padlocks to everyone, keeping for yourself the only key that opens them. Anyone who wants to send you a secret message puts it in a box and snaps one of your padlocks shut: from then on not even the sender can reopen it. Only you, with your key, can. The open padlock is the public key; the key that opens it is the private key.
- 01
Generation
Everyone creates a mathematically linked key pair.
- 02
Publication
The public key is distributed: on a website, in a certificate, in a message.
- 03
Encryption
The sender encrypts with the recipient’s public key.
- 04
Decryption
The recipient decrypts with their own private key.
- 05
Signature
The sender signs with their own private key; the recipient verifies with the sender’s public key.
Hybrid cryptography
Public-key algorithms are slow. In practice they are used to exchange or protect a random symmetric key, with which the data are then encrypted using a fast algorithm such as AES. This is what happens every time you open a site over HTTPS.
Public-key cryptography: history
From the secret insights of Britain’s GCHQ to Diffie and Hellman’s paper, from RSA to elliptic curves and certificate infrastructures.
The pages of this topic
Back to the overviewPublic-key cryptography: the maths
Trapdoor one-way functions: multiplication and factoring, modular exponentiation and the discrete logarithm.
Public-key cryptography: worked example
A digital signature with small numbers, using the example RSA keys, to see how private and public keys work together.
Public-key cryptography: weaknesses and attacks
The man-in-the-middle attack, weak keys, side channels and the quantum threat: where public-key cryptography can fail.
Public-key cryptography today
Where public-key cryptography is used every day: HTTPS, digital signatures, messaging, passkeys, cryptocurrencies, software updates.
Public-key cryptography: try it yourself
Exercises on modular exponentiation, one-wayness and verifying a signature, with solutions.
Public-key cryptography: frequently asked questions
Short answers to the most common doubts about public-key cryptography.