Key lifecycle và production operations
Phần khó nhất thường không phải thuật toán mà là generation, distribution, storage, access, rotation, revocation, backup và destruction.
Design
- Dùng KMS/HSM/secret manager; không hard-code key, commit keystore/password hoặc log plaintext/key.
- Tách Key Encryption Key (KEK) và Data Encryption Key (DEK); envelope encryption giảm dữ liệu phải gửi vào KMS.
- Ciphertext envelope lưu version, algorithm, key ID, nonce, AAD context và ciphertext/tag.
- Rotation cần dual-read/new-write hoặc rewrap/re-encrypt plan, telemetry và rollback.
- Least privilege theo encrypt/decrypt/sign/verify; audit use, rate, error và anomalous caller.
- Backup key phải khớp data RPO/RTO; crypto-shredding chỉ đúng khi mọi copy key không thể phục hồi.