Skip to content

// Security · 09

Encryption in Transit and at Rest

Plaintext on the wireleads toenvelope keysTLS 1.2+leads toEncrypted at rest

Encrypt data on the wire with TLS and on disk with managed keys.

How it fits together

Encryption in Transit and at Rest structure«client»BrowserHSTS: https onlyOrders APITLS 1.2+ onlyNetwork snifferPayments servicemTLS client certOrders databasePII: envelope encrypted«external»Key management (KMS)holds key-encryption key1 TLS handshake2 mTLS call3 PII envelope4 wrap data keysees ciphertext
uses / callscreatesfails / error path· numbered steps replay in order
  • Browser uses / calls Orders API (1 TLS handshake)
  • Orders API uses / calls Payments service (2 mTLS call)
  • Orders API creates Orders database (3 PII envelope)
  • Orders API uses / calls Key management (KMS) (4 wrap data key)
  • Network sniffer fails / error path Orders API (sees ciphertext)

Spot it

  • Login or API reachable over plain HTTP
  • Backup readable after a disk is lost
  • Encryption keys stored beside the data

It costs

Handshake cost and certificate upkeep; a lost key means lost data.

Go deeperThe full explanation and what to ask for · 1 min readExpand

Encryption in transit: TLS protects data between a client and a server, and between services. Require TLS 1.2 at minimum (1.3 where you can) and turn off older protocols. Redirect plain HTTP to HTTPS, and send HSTS so browsers refuse plain HTTP next time. Mutual TLS adds client certificates, so each service proves its identity to the other, which is useful inside the network too.

Encryption at rest protects copies: disks, snapshots, backups and exports. Volume encryption covers the platform. Field-level encryption covers sensitive columns that must stay protected even from database administrators. With envelope encryption, a data key encrypts each record or file, and a key-encryption key in a KMS wraps those data keys. Rotating the wrapping key means rewrapping the data keys, not re-encrypting all the data.

The hard part is keys. Store them in a KMS or HSM, never next to the data, restrict who may use them, and log their use. Test restores, because a lost key is lost data. Encryption does not stop an attacker who controls the running application, since that application can ask the KMS to decrypt. When NOT to encrypt everything: per-field encryption costs and makes search and indexing hard, so encrypt what the threat model says matters.

Ask for it

  • TLS 1.2+ / TLS 1.3
  • HSTS
  • mTLS (mutual TLS)
  • envelope encryption
  • data key vs key-encryption key
  • KMS / HSM

Require TLS 1.2+ on every endpoint, redirect HTTP to HTTPS, send Strict-Transport-Security max-age=31536000. Use mTLS between Orders and Payments with internal CA certificates renewed every 30 days. Encrypt backups with a KMS key; envelope-encrypt PII columns with data keys wrapped by it.