I'm building a web app. The app needs to keep certain data within the database very secure.
Please assume for the moment that I don't have a HSM or Key-Management facility and can't afford to implement one.
When storing away a user's data, I want to generate a random key and provide it to the user. This will not be stored anywhere on my server. This key will be used to encrypt the data.
I don't feel comfortable with the user having the only key required to decode the ciphertext, as I don't know how they're going to store it, whether they're going to email it around, etc.
As such, I intended to apply some further form of encryption on the server-side.
So first, I would encrypt the data using the random key provided to the user, and then encrypt that again, using either a static key, or a second random key which I WILL store on the server/db.
By not storing the random key provided to the user, the data remains protected if the server is compromised, as there is nowhere within the server or associated components that a hacker can obtain all the keys required to decrypt the data. They may get access to the static key, or second random key, but this won't be enough.
I was thinking of using AES for both the first and second encryption.
- Is this a bad idea?
- Should I instead create an encryption key that is a formula of the user's random key and the server-stored key, and then only encrypt once?
- Should I do something completely different?