CMD Guide
HomeSystem Design

Encryption

Step 31 in the System Design path · 4 concepts · 0 problems

0 / 4 complete

📘 Learn Encryption from zero

Start from the problem. You want to send a secret note across a crowded room where anyone can read whatever passes by. Write it in plain English and everyone sees it. Encryption is scrambling that note with a rule so only someone who knows the rule can unscramble it.

Analogy — the locked box. Picture a box with a padlock. Symmetric encryption uses one key that both locks and unlocks: fast and simple, but you and your friend must already share that one key — and handing it across the crowded room risks someone copying it. Asymmetric encryption solves this with two matched keys. Your friend publishes an open padlock (the public key) anyone can snap shut, but only their private key reopens it. You lock your note with their public padlock; only they can open it.

Worked example — how HTTPS (TLS 1.3) works. Your browser connects to a bank. (1) The bank sends a certificate containing its public key; the browser checks a Certificate Authority's signature to confirm it's really the bank. (2) Both sides run an ephemeral Diffie-Hellman key exchange — each sends a fresh, single-use public value, and from these they independently derive the same shared symmetric key without ever transmitting it. The bank's certificate key is used to sign its half so an attacker can't impersonate it. (3) The whole conversation then runs on fast symmetric AES-GCM. This is the hybrid model: asymmetric crypto only to authenticate and agree on a key, fast symmetric crypto for bulk traffic.

Key insight: because the session key is derived from ephemeral keys that are thrown away, even stealing the bank's long-term private key later can't decrypt past traffic — this is forward secrecy, and it's why modern TLS dropped the older "encrypt the session key with the server's RSA key" approach. Confidentiality always reduces to who holds the key, and for how long — design the key's lifecycle, not just the algorithm.

✨ Added by the guide to build intuition — not from the source course.

Lessons in this topic

🎯 Guided practice

  1. Easy — "Store user passwords." A candidate says "encrypt the passwords with AES." Step 1: ask what operation you ever need — you only need to verify a login, never to recover the original password. Step 2: recall encryption is reversible (a leaked key exposes every password), while a hash is one-way. Step 3: choose a slow, salted password hash (bcrypt, scrypt, argon2) — the per-user salt defeats precomputed rainbow tables and stops two identical passwords sharing a hash, the deliberate slowness (configurable work factor) throttles brute force. Step 4: on login, hash the input with the stored salt and compare. Pattern learned: match the tool to the operation — if you never decrypt, hash; encrypt only when you must read the plaintext back.
  2. Medium — "Let users send each other private messages; the company should never read them." Step 1: parse the constraint — "company should never read them" rules out server-side encryption alone, because if the server holds the key, the server can decrypt. This forces end-to-end encryption. Step 2: keys live only on user devices. Each user generates a keypair; the public key uploads to a server directory, the private key never leaves the device. Step 3: apply the hybrid pattern — encrypt the message body with a fresh random symmetric key (fast AES-GCM), then encrypt that small symmetric key with the recipient's public key. The server stores and relays only ciphertext. Step 4: the recipient uses their private key to unwrap the symmetric key, then decrypts the body. Step 5: name the trade-offs — server-side search and message recovery become impossible (lost device = lost history unless keys are backed up), and you need key verification (safety numbers / fingerprints) to stop a man-in-the-middle swapping public keys, since the server hands out the keys. Pattern learned: "who must be unable to read this?" decides where keys live, and that location dictates the architecture.

✨ Added by the guide — work these before the full problem set.

🧠 Review & recall

Active recall is what moves a topic into long-term memory. Flip each card before revealing, then test yourself — your results are saved on this device.

Flashcard
What is the core difference between plaintext, ciphertext, and the role of a key in encryption?
tap to reveal →
Encryption transforms readable data (plaintext) into a scrambled, unreadable format (ciphertext); turning ciphertext back into readable form requires the correct decryption key. Without the key, the data stays unreadable to unauthorized users.
💡 Plain in, scrambled out — only the right key reverses it.
Flashcard
How do symmetric and asymmetric encryption differ in their use of keys?
tap to reveal →
Symmetric encryption uses the same single key to both encrypt and decrypt (one key locks and unlocks the box). Asymmetric encryption uses two matched keys: a public key for encryption and a private key for decryption.
💡 Symmetric = one shared key; Asymmetric = public padlock, private opener.
Flashcard
In the HTTPS / TLS 1.3 hybrid model, why use asymmetric crypto AND symmetric crypto instead of just one?
tap to reveal →
Asymmetric crypto is used only to authenticate the server (via its certificate, checked against a Certificate Authority) and to agree on a shared symmetric key via ephemeral Diffie-Hellman. The bulk conversation then runs on fast symmetric AES-GCM, getting authentication plus speed.
💡 Asymmetric to agree, symmetric to stream.
Flashcard
What is forward secrecy and why did modern TLS adopt it?
tap to reveal →
Forward secrecy means the session key is derived from ephemeral (single-use, thrown-away) Diffie-Hellman keys, so stealing the server's long-term private key later cannot decrypt past traffic. Modern TLS dropped the older 'encrypt the session key with the server's RSA key' approach because that left past sessions exposed.
💡 Throwaway keys = yesterday's traffic stays secret.
Flashcard
Beyond confidentiality, what other security goals does encryption serve, and what are its main challenges?
tap to reveal →
It also provides privacy (keeping conversations private) and integrity (verifying data was not altered in transit). Main challenges are key management (a leaked key exposes the data), performance (encrypt/decrypt adds latency), and implementation complexity.
💡 Goals: privacy + integrity; Pains: keys, performance, complexity.
Flashcard
What is a DDoS attack and what are its three main categories?
tap to reveal →
A Distributed Denial of Service attack overwhelms a target server/service/network with a flood of traffic from many compromised machines (botnets, including IoT devices) to slow it down or shut it off. The three categories are volumetric (flood bandwidth), protocol (consume server/network resources), and application-layer (target specific app aspects).
💡 Many zombies flood one target — by Volume, Protocol, or App-layer.
Flashcard
Name key strategies for mitigating a DDoS attack.
tap to reveal →
Network redundancy (multiple traffic paths, no single point of failure), DDoS protection services that absorb/diffuse attack traffic, firewalls and anti-DDoS software, continuous traffic analysis to spot anomalies, a responsive incident plan, good security hygiene, and scalable cloud infrastructure to absorb spikes.
💡 Redundancy + scrubbing services + scale + a plan.
Q1. A candidate proposes 'encrypt user passwords with AES so we can verify logins.' What is the correct critique grounded in encryption fundamentals?
Q2. In the TLS 1.3 handshake described, what is the purpose of the server's certificate and the Certificate Authority's signature?
Q3. Why does deriving the session key from ephemeral Diffie-Hellman values provide forward secrecy?
Q4. Which option correctly matches a DDoS attack type to its description?
Q5. A service wants to keep running during a DDoS attack. Which combination of mitigations aligns with the lesson's guidance?