-
Notifications
You must be signed in to change notification settings - Fork 12
Description
I have a lot of pieces of data in a database, each encrypted and decrypted at different times.
Although the encryption key is likely to change rarely, I'd still like the ability to change it out smoothly without having to re-encrypt all of my data at one time, and cause downtime, as database access would have to be blocked while this takes place.
I think the best solution to this problem is to accept an array of keys. Encrypt only with the first, but attempt to decrypt with all, starting from the first, and going down the list, only returning null if all keys fail.
The hmac function should also return hmacs with all provided keys in that case, returned in the same order (so that one can match the key).
Having both of those will allow the relatively smooth migration of old data, where one could re-encrypt it either on modification, or on lookup through the hmac.
The alternative right now would be to have multiple SimpleEncryptor instances, but managing them would be somewhat of a hassle.