How does HTTPS keep your secrets safe?
Ever notice the little padlock 🔒 next to a website's address? That's HTTPS at work. Meet Amit, checking his balance on Bharat Bank's website — and let's follow exactly what his browser and the bank's server whisper to each other before a single rupee amount is shown!
📽️ Comic Strip: Amit Checks His Bank Balance
Same story, told in six panels — before we go step by step below.
✉️ Why bother with all this?
Plain HTTP is like an ordinary postcard sent by post. HTTPS is like a sealed, signature-required registered parcel.
HTTP — a plain postcard
Anyone handling it along the way — a nosy neighbor, the postman, someone at the sorting office — can flip it over and read every word, including your password and OTP.
HTTPS — sealed registered parcel
Your message travels inside a locked box with a wax seal, and only the person it's addressed to has the key. Anyone who intercepts it sees a locked box — nothing readable inside.
🗺️ The handshake, as a flow chart
All of this happens in a fraction of a second, before a single word of your actual message is sent.
"Shall we talk secretly?"
- Amit's browser sends a Client Hello message: a random number, the highest TLS version it supports, and a list of encryption methods ("cipher suites") it knows.
- This is all sent in the open — no secrets here yet, just an introduction.
The Client Hello also carries the SNI (Server Name Indication) field — literally the plaintext domain name (bharatbank.com), so a server hosting hundreds of websites on one IP knows exactly which certificate to hand back. This is also why network firewalls can still see which site you're visiting, even over HTTPS.
"Hello! Here's my ID card."
- The server sends back a Server Hello and its SSL/TLS certificate.
- That certificate holds the server's identity (
CN=bharatbank.com), its public key, a validity period, and a digital signature from a trusted issuer.
A real X.509 certificate is essentially a small signed document with fields like Subject, Issuer, Validity (Not Before / Not After), Public Key, and Signature Algorithm (e.g. SHA256withRSA). Type openssl x509 -in cert.pem -text -noout to see every field on a real certificate.
Checking the ID card is real
- The certificate is signed by a Certificate Authority (CA) — an organization trusted to verify identities, like DigiCert, Sectigo, or Let's Encrypt.
- Browsers and operating systems ship with a "root store" of trusted root CAs. If the signature traces back to one of them, the ID card is genuine.
- Wrong domain name, expired date, or unknown issuer → big red "Not Secure" warning.
Certificates form a chain: Leaf (bharatbank.com) → Intermediate CA → Root CA. Root CA keys are kept offline and almost never used directly — they sign intermediates instead, so if an intermediate is ever compromised, it can be revoked (via CRL or OCSP) without touching the root.
Click the padlock icon → "Certificate"
openssl s_client -connect example.com:443 -showcerts
Agreeing on a secret, out loud, safely
- The server's certificate contains a public key anyone can use to lock a message.
- Only the server's matching private key can unlock it — and that key never leaves the server.
- Both sides use this trick to agree on a brand-new shared secret, without ever saying it plainly.
Modern TLS mostly uses ECDHE (Elliptic Curve Diffie-Hellman Ephemeral) instead of plain RSA key exchange. Both sides generate a temporary key pair just for this one session and combine math to land on the identical shared secret — without ever transmitting it. Because the key is thrown away after the session, this gives Perfect Forward Secrecy (PFS): even if a server's long-term private key leaks years later, an attacker who recorded today's encrypted traffic still can't decrypt it.
Switching to a faster private language
- The padlock trick (asymmetric encryption) is clever but slow, so it's only used to safely share a secret.
- From here, both sides use that shared secret with fast symmetric encryption for the entire conversation.
A cipher suite like TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 is really four decisions bundled together:
ECDHE— how the key exchange happensRSA— how the server proves its identity (signature)AES_128_GCM— the actual symmetric cipher that scrambles your dataSHA256— the hash used inside the handshake for integrity
In TLS 1.3, this got simplified — only strong AEAD ciphers like AES-GCM and ChaCha20-Poly1305 are allowed. TLS 1.3 also cuts the handshake from 2 round trips down to 1 (sometimes 0 for repeat visits) — which is why modern sites feel noticeably snappier.
The real message, all scrambled up
- Every bit of your HTTP request and response is now encrypted before it ever leaves your device.
- Even the exact page you're viewing is hidden from anyone watching the network — only the destination address is visible.
It's not just about hiding the message — it's also about proving nobody tampered with it. Ciphers like AES-GCM are AEAD (Authenticated Encryption with Associated Data): every encrypted chunk gets a built-in authentication tag. If even one bit is flipped in transit, the tag check fails and the connection is dropped instantly.
The safety signal you can see
- Click the padlock any time to see who really issued the certificate.
- No padlock, or a warning triangle, means: stop and think before typing anything sensitive!
Well-run sites like a bank add an HSTS (HTTP Strict Transport Security) response header — a rule telling the browser "never even try plain HTTP for this domain again, for the next N days." This stops a whole class of attacks where someone tricks you into visiting the unencrypted http:// version first.
curl -v https://example.com 2>&1 | grep -i "SSL\|subject"
Shows the TLS handshake details and which certificate was presented.
🧩 HTTP vs HTTPS, side by side
| HTTP | HTTPS | |
|---|---|---|
| Default port | 80 | 443 |
| Encrypted? | No — plain text | Yes — fully scrambled |
| Browser icon | "Not Secure" | 🔒 Padlock |
| Identity check? | None | Certificate verified against trusted CA |
| Good for | Non-sensitive, static info only | Logins, payments, personal data — basically everything today |
🎓 Level Up: The Technical Deep Dive
For the curious ones who want to peek further under the hood.
⏱️ TLS 1.2 vs TLS 1.3
TLS 1.2 needs 2 full round trips before any data flows — Client Hello, Server Hello + Cert, key exchange, then Finished messages both ways.
TLS 1.3 (2018) squeezed this into 1 round trip, and added 0-RTT resumption for repeat visits — your second visit today can start sending encrypted data almost instantly.
🔁 Session resumption
Doing the full handshake every single time would be slow. So the server hands the browser a session ticket — an encrypted note it can show next time to skip straight to a shared secret, without redoing certificate checks from scratch.
🛡️ Perfect Forward Secrecy
Because each session's key is freshly generated and thrown away afterward (thanks to ECDHE), recording today's traffic and stealing the server's private key next year still won't unlock it.
🏷️ SNI — one server, many domains
A single AWS or hosting server often serves hundreds of websites off one IP address. Server Name Indication lets the browser say which domain it wants before encryption starts, so the server knows which certificate to present.
🧬 Anatomy of a cipher suite
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 broken down:
🔐 HSTS — no downgrade allowed
The response header Strict-Transport-Security: max-age=31536000 tells the browser to remember, for a full year, that this domain must always use HTTPS — closing the door on a common trick where an attacker quietly downgrades your first request to plain HTTP.
