Key
Management
Understand how cryptographic keys are generated, stored, and rotated to keep data secure throughout its lifecycle.
What Is a Cryptographic Key?
A cryptographic key is a string of data used by an algorithm to encrypt or decrypt information. Think of it as the secret ingredient that transforms readable plaintext into unreadable ciphertext, and vice versa.
The Key Lifecycle
Why Key Management Matters
Key Generation: The Foundation
Secure key generation depends on true randomness. Keys must be unpredictable to an adversary. The strength of a key is often measured by its entropy: the number of bits of randomness it contains.
Secure Key Storage
Once generated, keys must be stored so they remain confidential and available when needed. There are several approaches, each with trade-offs:
Key Rotation: Limiting Exposure
Key rotation means replacing an active key with a new one at regular intervals. Even if an attacker discovers an old key, they can only access data encrypted during that key's active period.
Symmetric vs Asymmetric Keys
| Symmetric | Asymmetric | |
|---|---|---|
| Keys Used | One shared secret key | Public + Private key pair |
| Speed | Fast | Slower |
| Key Distribution | Difficult (must share secretly) | Easy (public key is shared openly) |
| Examples | AES, ChaCha20 | RSA, ECC, Ed25519 |
| Key Length | 128 - 256 bits | 2048 - 4096 bits (RSA) |
| Use Case | Bulk data encryption | Key exchange, signatures |
The Core Principle
Separation of Duties
No single person should have access to both the key and the encrypted data. Splitting responsibilities across roles reduces the risk of insider threats and accidental exposure.
How to Apply Key Management
Example: TLS on a Web Server
Example: Database Encryption at Rest
Example: Responding to a Key Compromise
Common Mistakes
Key Management Summary
| Stage | Goal | Best Practice |
|---|---|---|
| Generation | Unpredictability | Use CSPRNG + HSM |
| Storage | Confidentiality | HSM or managed key vault |
| Distribution | Secure delivery | Asymmetric key exchange |
| Rotation | Limit exposure window | Scheduled + event-driven |
| Revocation | Immediate invalidation | CRL / OCSP |
| Destruction | Eliminate residual risk | Cryptographic erasure |
Question 1 of 5
What is the primary purpose of key rotation?
Question 2 of 5
Which of the following is the most secure method for storing cryptographic keys?
Question 3 of 5
In a hybrid cryptosystem (like TLS), what role does the asymmetric key pair play?
Question 4 of 5
A developer uses Math.random() in JavaScript to generate an encryption key. Why is this a critical security flaw?
Question 5 of 5
Kerckhoffs' Principle states that the security of a cryptosystem should depend entirely on: