Jacob Cannon Jacob Cannon - 18 days ago 6
PHP Question

How can I store sensitive data securely in a MySQL database?

I am making an employment application for a company I am working for. I've got it to protect against SQL injection and some XSS techniques. My main issue is keeping sensitive information secured, like SSN and address, because the company needs that to make 1099 forms for the salesmen's taxes.

I don't know how to do this part, but should I encrypt everything and then decrypt it when it gets into the MySQL database?

Answer

This is an overly simplified answer and should be taken with a grain of salt, as most answers about security:

  • Use SSL everywhere.

  • Use a secure encryption key

For storage of encrypted data, you could use a BLOB field, and use MySQL's built in encryption functions. Example:

update mytable set myfield = AES_ENCRYPT('some value', SHA2('your secure secret key', 512));

If you prefer to do the encryption/decryption in the application code, take a look at PHP's Mcrypt functions.

  • Encrypt the user input
  • Store in the database
  • Decrypt it after fetching it

This is by no means a complete guide, but it's a start and better than doing nothing.

You may be able to learn more on http://security.stackexchange.com/

Comments