HTTPS: how encryption works between browser and server
Simplified diagram of the asymmetric key exchange followed by symmetric session-key encryption.
This memo summarises, as a diagram, how HTTPS encrypts traffic between a browser and a web server: asymmetric encryption is used first to exchange a key, then symmetric encryption takes over.
Steps
- The browser initiates the connection and asks for an HTTPS connection.
- The web server, which holds a public key and a private key, sends back its public key.
- The browser generates a session key.
- It encrypts the session key with the server's public key and sends it.
- The server decrypts it with its private key and obtains the session key.
- Asymmetric encryption stops; both sides use the same session key (symmetric encryption) for the rest of the exchange.
Why two kinds of encryption
- Asymmetric (public key / private key) lets two parties exchange a secret without sharing anything beforehand, but it is expensive.
- Symmetric (session key) is fast, so it is used to encrypt the data exchanged.
Notes
This is a simplified view: real TLS also negotiates algorithms and verifies the server certificate.