My goal is to be able to encrypt the data so that no one would be able to make use of it if it was stolen.
- the one that will be encrypted
- can be any type of data
Data encryption key
- the key for encrypting and decrypting the user data
- stored encrypted
- does not change
- unique per user
- generated upon registration
- has two encrypted copies:
- 1st is encrypted and decrypted using the user's unencrypted password
- 2nd is encrypted and decrypted using the user's email
- used to encrypt and decrypt the 1st copy of data encryption key
- stored encrypted using bcrypt
- used to encrypt and decrypt the 2nd copy of data encryption key
- has a separate copy stored encrypted using bcrypt. The other copy was part of user data
When the user logs in, the submitted password will be verified using the stored encrypted password. If valid, his/her data encryption key will be decrypted using the same submitted password. The data encryption key can now be used to encrypt and decrypt the user data.
The user provides his old password. This will be used to decrypt the data encryption key which will then be encrypted using the new password.
The user is required to provide his username and email. This username will be used to find the separately stored encrypted email which will be used to verify the provided email. If both username and email are correct the provided email will receive a reset key. The reset key will allow the user to provide a new password. The 2nd data encryption key will be decrypted using the email and will be encrypted using the new password. The resulting value will replace the 1st data encryption key.
I am wondering if this is a viable scheme. I have not yet looked for a similar approach. If you know one, or has a better one please let me know.