1

I am trying to protect the data by using AES to encrypt all PII data before it is saved to database, and I think the general mechanism is something like below.

(This is what I think, not necessary correct)

User input data -> html sends data to web service via https -> web service encrypts the data using private key that is distinct to each user -> web service saves data to database

and on the other way:

User request data -> web service gets data from database -> web service decrypt the data -> web service sends back the data to user via https

For example, email is a PII field that is encryption protected. Say when user is registering, they provide an email and a password. Web service calculates a random private key and use that key to encrypt email, (Question I here.) and saves the encrypted email to database. When user wants to log in using the email and password combination, they again sends the email to web service (Question II here).

However the two questions arise:

  1. Should I store the private key in database? Should this be encrypted? If so, how can it be retrieved and decrypted? Otherwise what should we do about the private key?
  2. Assuming in question 1, we save the private key somewhere with user ID as PK. At the moment when user tries to login with email and password, the web app receives clear-text email without knowing the user ID. How should it decrypt the email without the user ID that is used to locate the private key? Without the private key, how can the system confirm the email is a valid email?

These may be basic questions but I just can't figure out... Wondering what the industry is using to solve the problems, or am I even on the right track?

1

Encrypting the private key as well really doesn't add much more security - ultimately you need to store some key unencrypted therefore it makes sense for that to be the PK.

Given the email address is encrypted (signed using the PK) you will need some additional information to perform the look up - the recommended solution is to use a public key. The public key is distributed to the clients and sent as part of the requests and used to lookup the PK and decrypt the data.

0

You may store the key in your database unencrypted. You may encrypt it with symmetric key which you and only you will know. You should decrypt the password you get and compare the value with your encrypted passwords in the database. You should never store such information in plain text in your database!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.