How should ‘sensitive’ data be stored in MySQL Database?
1) Should I focus more on the security of the MySQL database and store the data as plain text?
- I found a step by step tutorial on how to make a MySQL database more secure:
- http://www.symantec.com/connect/articles/securing-mysql-step-step
2) Should I encrypt the data?
- If yes, then how should the encryption be done?
- Using MySQL aes_encrypt/aes_decrypt?
- Using PHP AES functions/algorithm for encrypting/decrypting data?
- How should the data be stored in MySQL?
- BLOB
- BINARY
- VARBINARY
In my case the ‘sensitive’ data are payments done by individuals.
Thanks
It’s a mixture of both. Two existing answers (at the time I wrote this https://stackoverflow.com/a/10718397/1015483 and https://stackoverflow.com/a/10718459/1015483) are valid – you need to look at about 5 methods of possible attack that I can think of
But three elements not mentioned:
For part 2 of your question:
Using MySQL encrypt/decrypt functions will stop someone who has access to the raw data, but not MITM or SQL injection or even CSV dumps taken for transport.
So, IMO (and it’s only my opinion and the way I’ve done it) is to encrypt with PHP and sned the encrypted data over the wire, as that stops all methods of trapping the data, and a CSV dump will be “scrambled”.
If you do that, you may as well use the varbinary / blob types as it stops you accidentally trying to read/edit in phpMyAdmin. Plus potentially saves a few bytes nominally (although this depends on indexes and other stuff – so that alone is not a winning argument).
And now the down side: searching and sorting. Anything you index or search on, if encrypted, will only match the entire, exact, case sensitive string padded to the correct length (normally a search will be case insensitive, and you can do part searches with LIKE). And if you want to ORDER BY then you need the original strings. So bear than in mind when designing the structure.
Hope that helps.