According to some government standards I need to be able to ensure some data in a database has not been tampered with.
My current idea is to store a MAC (HMAC-SHA256) next to each instance of the serialized data. The key will be stored in a separate location but the same key will be used for every MAC.
To detect tampering, I will read the data, compute the MAC again with the same key, and compare the computed MAC with the one stored in the DB. If they are equal, the data has not been tampered with, if they are different, than the data has been tampered with.
A weakness I am aware of is that if the key were to be compromised, we no longer can trust the MACs or the data. It would be possible to recompute the MACs, but they would only be valid for the data in the DB which we can no longer trust.
A few questions:
- Is this a valid use case for a MAC?
- Are there any major or minor flaws with this technique?
- Is it OK to reuse the same HMAC key forever?
- Would an asymmetric or AEAD solution be preferable?