My use case:
I have few master keys, I use each for a specific operation (e.g. one for encrypting user's data and another for creating JWT signatures etc...).
I use these master keys in two specific things:
- in PBKDF2 as an input + a salt to derive symmetric keys and nonces (iv) and, then store the salt only with the ciphertext in the database
- in HMAC as a secret key (pepper)
I need to rotate these master keys when they get old.
Questions to clarify what I need to know:
- When do these master keys get old or need to be rotated ?
- How to rotate these keys and also can get back the old keys from the new keys to decrypt encrypted data or verify hashes that were made by these old keys ? I think I should do a bit-XOR on the old key with its corresponding new key
- I currently don't have the privilege of using HSMs (Hardware Security Modules) or secure enclaves, is storing these master keys in files beside the app API secure enough ? What things should I take in mind ?
- Am I fine with PBKDF2 or I'd better use a HKDF ? If yes, what other recommendations I should do when using HKDF ?
- What length recommendation for the master key in such a use case ?
- Is there any flows, problems or improvements in the whole thing ?