Real systems combine both families: public-key methods to agree on a key safely, and shared-key encryption for the actual data. You use this every time you open a secure website.
Hybrid encryption
Agreeing on a key in public
In 1976, Whitfield Diffie and Martin Hellman published a way for two parties to agree on a shared secret while an eavesdropper hears every message. Each side keeps a private number and sends a public value made from it. Each side then combines the other’s public value with its own private number, and both arrive at the same key. The eavesdropper, who has only the public values, cannot. This is called Diffie–Hellman key exchange, and versions of it run in almost every secure web connection.
- 1Your browser says hello
- 2The site proves who it is
- 3The two agree on a fresh shared key
- 4Everything after uses the shared key
- 5The key is thrown away at the end
Opening any https:// page runs a short conversation called the TLS handshake. It uses public-key methods for the start and shared-key encryption for the rest.
What happens when you open a secure site
The handshake in the figure is TLS, Transport Layer Security, the protocol behind https:// and the padlock. Its older versions were called SSL, and both SSL and the early versions of TLS are now retired. Use TLS 1.2 or 1.3. Making a new key for every session, and throwing it away afterwards, is called forward secrecy: stealing the site’s private key later does not let anyone decrypt old sessions that were recorded.
KEYS-3 counts as completed once you step through the figure to its last step.