Encryption Key Management Best Practices

Encryption key management is the foundation of data security. Strong encryption with weak key management provides no real security—the keys are the single point of failure.


Key Lifecycle


Key generation: Use cryptographically secure random number generators. Generate keys on hardware security modules (HSM) or using approved libraries. Key strength: AES-256 for symmetric encryption, RSA-3072 or ECC P-384 for asymmetric encryption.


Key distribution: Securely transfer keys to authorized systems. Never transmit keys over unencrypted channels. Use key exchange protocols (Diffie-Hellman, ECDH) for session key establishment. Out-of-band verification protects against man-in-the-middle attacks.


Key storage: Store keys separately from encrypted data. Production keys in HSMs or key management services. Development keys in secure vaults (HashiCorp Vault, AWS Secrets Manager). Never store keys in code, config files, or environment variables.


Key rotation: Rotate keys on a regular schedule (annually for most keys, monthly for high-security keys). Automated rotation without data re-encryption (envelope encryption: rotate key encryption keys, not data encryption keys). Emergency rotation on suspected compromise.


Key revocation: Revoke compromised keys immediately. Key revocation lists distributed to all authorized systems. Grace period for key replacement. Audit key revocation events.


Hardware Security Modules


HSMs are dedicated hardware for cryptographic operations. They provide tamper-resistant key storage and certified random number generation. Cloud HSMs (AWS CloudHSM, Azure Dedicated HSM) provide HSM capabilities as a service.


HSMs perform encryption/decryption operations without exposing keys. Keys never leave the HSM in plaintext. HSMs are required for compliance standards (PCI-DSS, FIPS 140-2). Performance: modern HSMs handle 10,000+ cryptographic operations per second.


Cloud KMS


Cloud key management services (AWS KMS, Azure Key Vault, GCP Cloud KMS) provide managed key storage. Automatic key rotation, audit logging, and access controls. Integrated with cloud services for transparent encryption.


Envelope encryption encrypts data with a data encryption key (DEK), then encrypts the DEK with a key encryption key (KEK) stored in KMS. This allows high-performance encryption with centralized key management. KMS handles KEK management; applications manage DEKs.


Key Management in Applications


Never hardcode keys. Use environment variables for development. Use secrets management tools (HashiCorp Vault, AWS Secrets Manager) for production. Vault provides dynamic secrets, automatic rotation, and audit logging.


Hashicorp Vault is the most popular secrets management tool. It stores API keys, database credentials, and encryption keys. Dynamic secrets generate credentials on-demand with automatic expiration. Vault Agent handles authentication and secret injection for applications.


Auditing


Log all key management operations: creation, rotation, revocation, and access. Centralize logs for security monitoring. Alert on anomalous key access patterns. Regular key usage audits verify that only authorized systems use each key. Review key permissions quarterly.