Module 10 · Lesson 02

Protecting data in transit, at rest and in backups

Encryption is not a checkbox; it is a decision about who holds the key.

Intermediate 7 min read Updated 2026-11-02

What you will be able to do

  • Explain what TLS protects and what it does not
  • Choose between hashing, encryption and tokenisation
  • Design key rotation without downtime
  • Reduce blast radius by minimising stored data

Transit

TLS terminates somewhere: at the load balancer, at the gateway, or inside each service. Once terminated, traffic inside the network is plaintext unless you re-encrypt. Most designs assume a trusted network and terminate at the edge; regulated data usually calls for mTLS between services so a compromised host cannot sniff the mesh.

  • Certificates need lifecycle. Automated issuance and renewal, with alerts before expiry.
  • Redirect and HSTS. Plain HTTP should never serve application data.
  • Pin nothing casually. Certificate pinning breaks clients when you rotate; use it only with a rotation plan.
  • Do not log headers. Authorization and cookies end up in logs more often than anyone expects.

At rest, and the three techniques

TechniqueReversibleUse for
Hashing + saltNoPasswords, API keys, deduplication fingerprints
Encryption (AES-GCM)Yes, with a keyPII you must display, payment references, messages
TokenisationVia a vaultCard numbers, SSNs, anything a third party must not hold
Field-level encryptionYes, per fieldA few sensitive columns inside an otherwise normal table
Full-disk encryptionTransparentStolen disks and backups, not application access control
row: { id, tenant, card_token, last4, created_at }

card_token -> vault/lookup service
vault holds the encrypted PAN under a key that the
application never sees directly (envelope encryption)

Tokenisation is the strongest move because it removes the sensitive value from the system that has the most queries and the most bugs. The application stores a reference; the vault handles decryption, access logging and rotation.

Encryption without key management is theatre
A key committed to the repository, or stored beside the encrypted data, protects against nothing. Keys belong in a KMS with an audited access policy and rotation.

Key rotation, briefly

Version every ciphertext
Store a key id with each encrypted value so old data remains decryptable.
Introduce the new key
Start encrypting new writes with key v2 while v1 stays available for reads.
Re-encrypt lazily
Rewrite rows on read or in a background job; avoid a single mass re-encryption event.
Retire the old key
Delete v1 only after a verified zero-usage period, with a rollback window.

The cheapest protection: not storing it

Every field you keep is a field that can leak, must be encrypted, must be backed up, and must be deleted on request. Ask in the design: do we need the full card number, or the last four and a token? Do we need a precise birth date, or an age band? Minimisation shrinks the blast radius before any cryptography is applied.

AES-GCM throughput
1-5 GB/s
Hardware accelerated; rarely the bottleneck
bcrypt cost 12
~250 ms
Deliberately slow; rate-limit login
KMS decrypt
1-10 ms
Cache data keys, not plaintext
Backup retention
set by policy
Deletion must reach backups too
Two sentences are enough
"TLS at the edge and mTLS inside; PII encrypted with per-tenant keys from a KMS; card data tokenised so the primary store only holds a reference. Backups inherit the same key policy."

Worth remembering

  • TLS protects the wire, not the endpoint — a compromised server still sees plaintext.
  • Passwords are hashed with a slow algorithm and a per-user salt; they are never encrypted, because you must never need them back.
  • Tokenisation replaces sensitive data with a reference, shrinking the scope of what must be encrypted.
  • Keys belong in a managed key service with rotation, not in a config file or a repository.

Checkpoint

Answer all 3 questions to finish the lesson.
1. Why are passwords hashed rather than encrypted?
Hashing is one-way by design. If the system can recover a password, so can an attacker who compromises it.
2. What does TLS protect?
TLS secures the channel. Both endpoints still see plaintext, so server compromise or logging can expose data.
3. How should encryption keys be managed?
Keys stored beside the data provide no separation. A KMS gives audited access, versioning and rotation.