This is a mixture of both. The two existing answers (at the time of writing this fooobar.com/questions/1413915 / ... and fooobar.com/questions/1413915 / ... ) are valid - you need to look at about 5 possible attack methods that I can think of
- They gain access to your database server; so yes, ensure that the child is just as reasonable (Matt replied).
- Offline data capture (someone gets to your database data in some other way, maybe backup, maybe they guess the password, maybe MITM if you transfer data from one place to another). To do this, you encypt your data. For some reason, you can also do a CSV dump and send someone an email. Oops But this is happening. So encrypt (vlzvt answer)
But three elements are not mentioned:
- They can access your web server (if it is different from your database server). If they have access to the web server, all bets are disabled, since they have their own password, the key is the key to success. Therefore, you need to make it even more secure than the database server. (Matt may have meant higher, but just make it clear)
- As above, but do not forget if anyone is accessing phpMyAdmin or your management consul. Do not use access to open passwords with clear text or config for access.
- Finally, your application in itself (and the most difficult to block). You need to prevent the use of SQL injections that can reveal data. Data encryption would stop minimizing problems if someone got access through an incomplete request - therefore, encryption is the solution for this.
For part 2 of your question:
Using the encryption and decryption functions of MySQL will stop someone who has access to raw data, but not MITM or SQL injections or even CSV dumps taken for transportation.
So, IMO (and this is just my opinion and how I did it) is to encrypt using PHP and hammer encrypted data over the wire, as this stops all data capture methods, and CSV dump will be "scrambled".
If you do this, you can also use the varbinary / blob types, as this prevents you from accidentally reading / editing in phpMyAdmin. Plus, potentially saving a few bytes nominally (although it depends on indexes and other things - so one is not a winning argument).
And now the downside: search and sort. Everything that you index or search, if encrypted, will only match the entire, case-sensitive string, filled to the desired length (usually the search will be case-insensitive, and you can search for details using LIKE). And if you want ORDER BY, you need the source strings. So you should not keep in mind when designing a structure.
Hope this helps.
source share