

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Encrypting Data at Rest
incomplete
2: Key Management and Rotation
incomplete
3: Password KDFs
incomplete
4: Salts
incomplete
5: Argon2 Parameters
incomplete
6: Encrypted Files
incomplete
7: Secure Database Practices
incomplete
8: Personally Identifiable Information
incomplete
9: Financial Data
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Encrypted data is only as safe as the key used to encrypt it. But a single unversioned key means replacing it makes every value encrypted with the old key unreadable!
Instead, use a keyring. This isn't as complex as it sounds: start with one key and call it version 1 (v1):
DATA_ENCRYPTION_ACTIVE_VERSION=v1
DATA_ENCRYPTION_KEY_V1=<64 hex characters>
Then, whenever you encrypt a value, store its key version with the ciphertext:
| Ciphertext | Key Version |
|---|---|
0xdeadbeef... |
v1 |
0xfeedface... |
v1 |
| ... | ... |
When you need to rotate your key, add a new one and change the active version:
DATA_ENCRYPTION_ACTIVE_VERSION=v2
DATA_ENCRYPTION_KEY_V1=<old key>
DATA_ENCRYPTION_KEY_V2=<new key>
Your application should always decrypt with the version recorded on the payload and encrypt with the current active version. That way, old ciphertext remains readable after rotation.
If a key was compromised, rotate it and re-encrypt live data as soon as you can. This limits future exposure, but it can't protect ciphertext an attacker already copied with the old key.
Losing an encryption key can mean permanently losing the data it protects. Treat rotation, backup recovery, access control, and key retirement as one lifecycle.
A TOTP secret is a long-lived authentication credential. Bearly Secure must decrypt it to verify codes, so hashing isn't an option. The keyring can instead encrypt active and pending secrets at rest.
Bearly Secure already routes TOTP secrets through the keyring and includes a transactional startup migration for existing plaintext records. The keyring's Encrypt and Decrypt methods are still insecure pass-throughs, and the server doesn't require or inject a configured keyring yet.
Bearly Secure needs to rotate encryption keys without losing protected data. Complete and activate the versioned keyring so TOTP secrets are encrypted at rest.
Run and submit the CLI tests from the project root.