Open rhnkyr opened 4 years ago
You may use the key($key)
function in the facade to set one encryption key per user.
You can ask the user password and use pbkdf2 to generate a safe hash to use as key : https://www.php.net/manual/en/function.hash-pbkdf2.php
@leonekmi but with this technique if the user change his password you have to re-encrypt all the files, no ?
I would love also to know if with this technique it's required to re-encrypt all files when the user changes its password.
Sure, but you can probably create a background task after the user changes his password. Assuming you ask the old one for stealth checks, you can decrypt the data and encrypt it again with a new key (aka the new password).
Right but if the user own big amount of files, that could be a heavy task. Why not use a hash of a user data that won't change, as user uuid for example ;)
It kinda defeats the purpose of having an encrypted vault if the uuid or any other "non changing informations" is stored into your database "as is", why encrypt it then? It's only useful then if you don't trust the external provider for your data (S3 for example), but it would be misleading to say to your users that data is encrypted, because if you have the keys available with a simple request as an admin, the data is not really encrypted in a way that would actually be protecting user data.
What about generating a random key to encrypt the data, and then use pbkdf2 to store that key? That way if the user changes the password, we only have to re-encrypt the stored key again with pdbkdf2, not all the data. Would that be a good aproach (from a security point of view)?
Hi, I come back on that question because it's my dev time to shield my app. After skimming the crypto and security forums about per user encryption, I realised that my first proposition (with user id) was far from reality ^^ @underdpt your is a good choice I think, the one well described there https://security.stackexchange.com/questions/157422/store-encrypted-user-data-in-database The user and only can decrypt his encrypted data.
The only thing blocking for me now is if the user loses his password, he loses the key too, no way... I have to let the user access a forget password process in my app. A solution could be to also pbkdf2 store the initial random key with another user passphrase or question/answer asked at user registration like the password. My app could ask the passphrase to allow user to reset his password if he forgot it and get the encryption key. The encryption key would then be re-encrypted with the new password. Would that be a lack of security ? Any idea ?
Hi @soarecostin,
I would like to know which approach is the best for my question?
Thanks in advance.
Cheers.