1st Principles

Security · 32 min read

Encryption

Transforming data so only holders of the right secrets can read or forge it: confidentiality, integrity, and authenticity on public networks.

Why this exists

The internet is a shared medium full of observers and attackers. Without cryptography, cafe Wi-Fi is a party line and stored passwords are a breach waiting to happen.

Encryption and related primitives let strangers communicate privately, detect tampering, and authenticate endpoints without trusting every cable and router in between.

This lesson is the general toolkit: what problems the primitives solve and how they compose. HTTPS/TLS is the concrete application to web transport.

Axioms & primitives

  1. 01Confidentiality hides content from eavesdroppers.
  2. 02Integrity detects tampering; authenticity binds data to a party.
  3. 03Security lives in keys, protocols, and correct use, not in hiding the algorithm.
  4. 04Symmetric crypto shares one secret; asymmetric crypto uses key pairs.
  5. 05A hash is a fingerprint, not encryption.
  6. 06Protocols fail more often from misuse and poor key handling than from broken math in standard algorithms.

Learning objectives

After this lesson you should be able to:

  • Distinguish confidentiality, integrity, and authenticity with one concrete example each.
  • Explain why password storage should use slow hashing/KDFs rather than reversible encryption in the common case.
  • Contrast symmetric and asymmetric encryption roles in a handshake story.
  • State Kerckhoffs's principle in your own words.
  • Identify whether a failure is 'wrong primitive' or 'wrong key management'.

Progressive depth

Read the layers in order for a full explanation. Or open the layer you need.

01

Intuition

On a shared network, assume someone can copy your packets. Encryption rearranges bits so the copy is useless without keys. Authentication and integrity checks make forged or altered copies detectable.

You already rely on this whenever a lock icon appears: your browser and a server agree on keys, then speak in a form routers can forward but not usefully read.

Cryptography does not remove the need to decide whom you trust. It reduces how much you must trust the wires between you.

02

Formal shape

Symmetric encryption (AES-GCM and friends) uses the same key to encrypt and decrypt; it is fast for bulk data. Asymmetric encryption and signatures (RSA, elliptic curves) use key pairs; they excel at bootstrapping trust and key exchange, not at bulk throughput.

Hash functions map arbitrary data to fixed-size digests. They should be one-way and collision-resistant for their threat model. MACs and signatures bind digests to keys or identities.

Authenticated encryption (AEAD) combines confidentiality with integrity. Modern TLS prefers AEAD ciphersuites.

Password storage: store a slow, salted KDF output (Argon2, bcrypt, scrypt), not reversible ciphertext of the password and not a bare fast hash. Verification recomputes and compares.

03

Worked examples

Messaging app: perform a key exchange authenticated by identities, then encrypt each message with a symmetric key. Routers see ciphertext lengths and timing, not plaintext.

Password database breach: if passwords were stored with a proper KDF, attackers must grind guesses per user. If stored in reversible encryption with a leaked key, the breach is immediate plaintext.

File download integrity: publish a hash over HTTPS from a trusted site; users verify the file matches. The hash alone on an untrusted mirror is weaker without a trust anchor.

Failure mode: inventing your own 'XOR with password' scheme. The math looks clever until it meets real attackers. Prefer vetted libraries and protocols.

04

Edge cases

Metadata leaks: lengths, timing, IPs, and DNS names often remain visible even when payloads are encrypted.

Key compromise retrospectively decrypts recorded ciphertext unless forward secrecy was used.

Side channels (timing, power, shared caches) can leak keys from otherwise correct algorithms.

Legal and operational realities: key escrow, device seizure, and phishing bypass cryptography by attacking humans and endpoints rather than AES.

Mental models

  • Locked box vs wax seal

    Confidentiality is the locked box. Integrity/authenticity is the wax seal that shows tampering and who sealed it. Real systems need both.

  • Shared house key vs mailbox slot

    Symmetric keys are shared house keys: fast, but distribution is hard. Public keys are like a mail slot: anyone can insert, only the owner opens.

  • Fingerprint, not envelope

    Hashes identify content. They do not hide content. Publishing a hash is not encrypting the file.

  • Protocol as choreography

    Primitives are dance moves. A handshake is the choreography. Wrong order still fails even with strong moves.

Common misconceptions

  • Myth

    Encryption means the website is trustworthy.

    Reality

    Encryption can protect a channel to a phishing site just as well as to your bank. Authenticity of the peer is a separate question from ciphertext strength.

  • Myth

    A secret algorithm is stronger than a public one.

    Reality

    Kerckhoffs's principle: assume the attacker knows the algorithm; strength must live in the keys and correct protocol use.

  • Myth

    HTTPS is the same topic as password hashing.

    Reality

    Transport encryption protects data in motion. Password hashing protects stored verifier at rest. Related toolkit, different jobs.

  • Myth

    If it is encrypted, integrity is automatic.

    Reality

    Classical encryption without authentication can allow malleability. Modern designs use authenticated encryption.

Exercises

Work these without looking up answers first. Check yourself against the intent notes.

  1. Exercise 01

    For each goal, name the right tool class: (a) hide a file from a thief with the disk, (b) detect if a firmware image was altered, (c) prove a message came from a holder of a private key.

    What good looks like

    a encryption (or disk encryption), b hash/MAC/signature verify, c digital signature.

  2. Exercise 02

    Why is 'encrypt passwords with AES and store the ciphertext' usually worse than a password KDF for login verification?

    What good looks like

    AES implies recoverable secrets and key management; login needs one-way verifiers resistant to offline guessing.

  3. Exercise 03

    State Kerckhoffs's principle and give one reason secret algorithms fail in practice.

    What good looks like

    Security in keys not secrecy of algo; secret algos get reverse engineered and cannot be publicly reviewed.

Sources & further reading

External references. Prefer primary documents and clear explainers.

Go deeper on your own

These picks go past the foundation in this lesson. Use them when you want a primary spec, official docs, or a longer walkthrough.