← Concepts

阅读中文版本

Encryption at Rest

Encryption at rest protects stored data, backups, and disks with keys held in a KMS. It defends against media theft but not against a compromised application or SQL injection.

security

Definition

Encryption at rest is the practice of encrypting data before it is persisted to disk, object storage, a database, or backup media. Keys are managed separately from the data, often through envelope encryption in a key management service, so that possession of the storage medium alone does not reveal plaintext.

Context and scope

Encryption at rest applies to databases, object stores, snapshots, laptops, and removable media. It is commonly required by compliance frameworks and is one layer of a broader data protection strategy that includes TLS and access control.

Common misconceptions

  • Encryption at rest prevents SQL injection or application-level data theft
  • Full-disk encryption protects data from an attacker who can query the running application

Anti-patterns

  • Storing encryption keys alongside the encrypted data in the same database
  • Treating encryption as a checkbox without controlling key access and audit logs

Related concepts

Related examples

Authoritative source

https://csrc.nist.gov/pubs/sp/800/111/final

How encryption at rest works

Data is encrypted before it is written to disk, an object store, a database, or a backup. Keys live in a key management service (KMS) or hardware security module, separate from the data. Most cloud designs use envelope encryption: the KMS issues a data encryption key (DEK), the application encrypts records with the DEK, and the KMS wraps the DEK with a long-lived key encryption key (KEK). Ciphertext stores the wrapped DEK and a key ID.

When to use it

Use it for databases, object storage, backups, snapshots, laptops, and removable media. It is mandatory for many compliance regimes and essential when storage can be detached or copied. Pair it with TLS for data in transit and with field-level encryption for especially sensitive values. Encryption at rest is not a substitute for access control, because the application still needs authorization checks.

Trade-offs

Key management dominates the cost: misconfigured policies, lost keys, and cross-region replication are common failures. Encryption can break database indexing, sorting, and analytics unless you use deterministic or searchable schemes, which leak patterns. Performance overhead is usually small with AES-NI but measurable for large writes. Rotation requires re-encrypting data or rewrapping keys.

Example

const { Plaintext, CiphertextBlob, KeyId } = await kms.generateDataKey({
  KeyId: kekId,
  KeySpec: 'AES_256',
});
const ciphertext = encrypt(Plaintext, record);
await db.put({ id, ciphertext, keyId: KeyId, wrappedKey: CiphertextBlob });

Decrypt by unwrapping the DEK with the stored key ID, then decrypting the record. Never log plaintext keys.

Encryption at rest does not stop SQL injection, a compromised application, or an authorized insider reading through the API. Full-disk encryption protects a stolen disk, not a running server. Encrypting data without controlling key access provides little value. Related concepts include key rotation, TLS, and secret management.