Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 38 ยท Network and Data Protection

Encryption at Rest and in Transit

Learn how cloud encryption protects stored data and network traffic: AES, TLS, certificates, integrity with HMAC, and what encryption does and does not protect, with runnable demos.

Encryption turns readable data into scrambled data that only someone with the right key can read. In the cloud it is one of your most important data controls, and most providers make it easy: tick a box, or it is already on. The danger is thinking that encryption alone makes data safe. This lesson explains the two main places data is protected, what the guarantees are, and where they stop.

Data at rest, in transit and in use

Three states of data

At rest On disks, buckets, backups
In transit Moving over networks
In use In memory while processed

Rest and transit are standard; use is covered by confidential computing.

1 / 2
  • At rest: data stored on disks, in object storage, databases, snapshots and backups. Protects against stolen disks, discarded hardware and some forms of unauthorized access at the storage layer.
  • In transit: data moving between a user and a service or between services. Protects against eavesdropping and tampering on the network.
  • In use: data in memory while being processed. Specialized hardware features called confidential computing can encrypt memory and isolate workloads, for very sensitive cases.

Encryption at rest

Almost every cloud storage service supports server-side encryption, usually with AES-256. The key can be managed in three ways:

  1. Provider-managed keys. Easiest and often default; the provider handles everything.
  2. Customer-managed keys in the cloud key management service. You control the key policy, rotation and the ability to disable it, and every use is logged. (Key management is the next lesson.)
  3. Client-side encryption. You encrypt before upload and keep the keys; the provider only ever sees ciphertext. Strongest control, more work, and you must never lose the keys.

Encryption at rest also applies to snapshots, backups, logs and replicas; check that copies inherit it.

What at-rest encryption does not do. An authorized user (or an attacker holding their credentials) asks the service to read an object, and the service decrypts it transparently. Encryption at rest protects against loss of the storage media, not against a compromised identity. Access control still does that job.

Encryption in transit

Use TLS (Transport Layer Security) for every connection: browser to service, service to service and to databases. TLS provides:

  • Confidentiality through symmetric encryption of the session.
  • Integrity so modified data is detected.
  • Authentication of the server (and optionally the client) through certificates.

Practical rules:

  • Allow only TLS 1.2 or newer; prefer 1.3. Disable older protocols and weak ciphers.
  • Redirect HTTP to HTTPS and send the HSTS header so browsers refuse plain HTTP.
  • Use certificates from a trusted authority, with automatic renewal, and keep private keys in a key store.
  • Enforce TLS on storage and database endpoints (many have a "require secure transport" option).
  • Use mutual TLS (mTLS) inside service meshes so services prove their identity to each other.
  • Use IPsec VPN or a private link for network-to-network connections.
sequenceDiagram
    participant C as Client
    participant S as Server
    C->>S: Hello, supported versions and ciphers
    S->>C: Certificate, chosen cipher
    C->>C: Verify certificate chain and name
    C->>S: Key exchange
    Note over C,S: Both derive session keys
    C->>S: Encrypted application data

Simplified TLS handshake: the client checks the server's certificate before any data is sent.

Integrity: encryption is not enough

Encryption hides content, but it does not always stop modification. Good designs use authenticated encryption (such as AES-GCM or ChaCha20-Poly1305) which also detects tampering, or add a message authentication code (MAC) such as HMAC.

The next example uses only the standard library. It shows an HMAC tag detecting a change to stored data. (It demonstrates integrity only; for real encryption use a vetted library and an authenticated mode.)

Python Detect tampering with HMAC

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Without the key, an attacker cannot produce a valid tag for changed data, so any modification is caught.

A toy cipher to see the idea

To see what encryption does conceptually, this demo builds a keystream from HMAC-SHA256 and XORs it with the message. This is a teaching construction, not a production cipher. In practice use AES-GCM or ChaCha20-Poly1305 from a maintained library, never your own design.

Python Why nonces matter (toy stream cipher)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The lesson here is real: reusing a nonce (a number used once) with the same key breaks the security of many ciphers. Authenticated libraries handle nonces for you, which is one more reason not to write your own.

Checklist for cloud data

  1. Turn on encryption at rest for every store, snapshot and backup; choose customer-managed keys for sensitive data.
  2. Require TLS 1.2+ everywhere, including internal traffic and database connections.
  3. Use authenticated encryption and let vetted libraries or the service manage nonces and modes.
  4. Keep keys separate from data and restrict who can use them.
  5. Test restores and certificate renewals before they matter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does encryption at rest mainly protect against?

    The service decrypts for authorized callers, so access control must handle stolen identities.
  2. 2. Which TLS setting is recommended today?

    Older protocols have known weaknesses; internal traffic should be encrypted too.
  3. 3. Why use authenticated encryption such as AES-GCM?

    Authentication tags reveal tampering that plain encryption can miss.
  4. 4. What goes wrong if a nonce is reused with the same key in a stream cipher?

    Identical keystreams cancel out when ciphertexts are combined, revealing relationships between messages.

Summary

  • Protect data at rest, in transit and, for the most sensitive cases, in use.
  • Server-side encryption protects media, not stolen identities; choose provider, customer-managed or client-side keys by sensitivity.
  • Use TLS 1.2 or newer everywhere, HSTS for websites and mTLS between services.
  • Prefer authenticated encryption from vetted libraries; never reuse nonces or invent ciphers.

Next: Key Management: KMS, HSM and Envelope Encryption