mohsen dorparasti
mohsen dorparasti

Reputation: 8415

use each user's password as encryption key for his own data

I want to encrypt user's personal data then save them in database .

the encryption must be done in application ( I can't do that in sql server side )

now I wonder if it's possible to use each user's password to encrypt and later decrypt their data ? what are pros and cons of this approach /

Upvotes: 0

Views: 324

Answers (2)

Rohan
Rohan

Reputation: 340

You've said that you want to store secure personal data of a user. Doing this unless the personal info. is extremely sensitive is generally NOT recommended for a number of reasons. What is commonly done however is hashing + salting of the user's password.

This page has a good explanation on how hashing and salting works and why it's better than encrypting, and then decrypting the password.

http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/

As for encrypting the user's personal information, just like a password we can use a custom salt + hashing algorithm that's quite simple but effective on our application to use the custom hash equivalent of the userID which is expected to be permanent, static and persistent forever.

Since the uID (or a specialized unique string for every user) can be hidden from normal public and we ensure that our custom shared function cannot be accessed from unauthorized sources, we have a solid secured system.

This means, we hash+salt personal info based on a unique string such as a userID and a hash+salt the user's password aswell. For the personal information to be decrypted, both the userID hash and password hash should match with the database.

A better approach would just be to use known encryption protocols within your program. Data sent via HTTPS TLS for example is quite secure if implemented right.

Upvotes: 0

Hans Kesting
Hans Kesting

Reputation: 39284

One big 'con': what if the user changes his/her password? Then you would need to re-encrypt all data!

Upvotes: 2

Related Questions