Create, store, use, rotate and retire encryption keys safely, with a service that never shows the key.
A Key Management Service (KMS) creates, stores, uses, rotates and retires encryption keys. Its big promise: the master key never leaves it. You send data (or a small data key) to the KMS, and it sends back the encrypted or decrypted result.
Encryption is only as strong as the protection of its key. If a key sits in a config file next to the data, an attacker who gets one gets both. A KMS solves this by being a small, hardened service whose only job is to hold keys and do cryptographic work with them. Many are backed by HSMs (hardware security modules), special devices built so that keys cannot be copied out.
You already know envelope encryption from the Encryption at Rest topic: each piece of data gets its own data encryption key (DEK), and a master key inside the KMS wraps (encrypts) that DEK. This topic is about running that safely day to day: who may use a key, how often to rotate it, what happens when it is lost, and how to delete data by deleting a key.
| Stage | What happens | Good practice |
|---|---|---|
| Generate | A strong random key is made inside the KMS or HSM | Never make keys in app code or on a laptop |
| Store | The key is kept in hardware or an encrypted store | No plain copy outside the KMS |
| Use | Apps call encrypt, decrypt, wrap, unwrap or sign | Least privilege, one purpose per key |
| Rotate | A new key version is created and used for new work | Automatic on a schedule, and after any suspected leak |
| Revoke / disable | The key is turned off so it cannot be used | Used in an incident, can be undone |
| Destroy | The key is deleted for good | Use a waiting period, and be sure nothing still needs it |
| Model | Who controls the key | Trade-off |
|---|---|---|
| Provider-managed | The cloud provider, by default | Easiest. You trust the provider fully. |
| Customer-managed (CMK) | You control policy, rotation and deletion in the provider's KMS | A good middle ground and the usual choice |
| BYOK (bring your own key) | You make the key and import it | More control, more work. A copy exists outside the KMS. |
| HYOK / external key store | The key stays in your own HSM and the cloud calls out to it | Most control, but if your HSM is down, the cloud data is unreadable |
A simulation with no real cryptography. Real KMS services also keep older key versions so data wrapped by them can still be unwrapped.
dek_plain, dek_wrapped = kms.generate_data_key(key_id) ciphertext = aes_gcm_encrypt(dek_plain, data) store(ciphertext, dek_wrapped) # never store dek_plain forget(dek_plain) # to read: dek_plain = kms.decrypt(dek_wrapped) # KMS checks policy and logs it data = aes_gcm_decrypt(dek_plain, ciphertext)
| Term | Meaning in easy words |
|---|---|
| KMS | Key Management Service: a service that makes, stores and uses keys safely |
| HSM | Hardware security module: a device that holds keys and does crypto without letting keys out |
| DEK | Data encryption key: encrypts the actual data |
| KEK | Key encryption key: wraps and unwraps other keys |
| Master / root key | The top key, kept inside the KMS or HSM |
| Wrap / unwrap | Encrypt or decrypt a key with another key |
| Envelope encryption | Data encrypted by a DEK, and the DEK wrapped by a master key |
| Key rotation | Replacing a key with a new version on a schedule |
| Key version | One generation of a key, kept so old data can still be read |
| Crypto-shredding | Deleting data by destroying the key that encrypts it |
| BYOK / HYOK | Bring your own key / hold your own key, for more customer control |
| Separation of duties | The people who manage keys are not the ones who use them |
| Key escrow | A secure backup of a key, to recover from loss |
| Choice | We gain | We lose |
|---|---|---|
| Provider-managed keys | Zero effort | Less control and proof |
| Customer-managed keys | Control over policy and deletion | You own the mistakes |
| Key per tenant | Easy per-tenant erase, isolation | Many keys to manage and pay for |
| Cache DEKs | Faster, fewer KMS calls | Keys sit in memory for a while |
| External key store (HYOK) | Keys never in the cloud | Cloud data depends on your HSM being up |