From a 2012 Smashing Magazine article quite a bold statement is made to avoid AES in MySQL itself. Or as they put it "Why Should You Avoid AES In MySQL?". However, if you search for SQL encryption, you often find the AES_ENCRYPT
from (My)SQL mentioned. I am not saying that many search results mean the statement is untrue, but it just got me thinking: are the three quoted reasons below actually true?
What do the security experts here think about the reasons "why PHP’s Mcrypt is superior to MySQL’s AES functions":
- MySQL needs a database link between the application and database in order for encryption and decryption to occur. This could lead to unnecessary scalability issues and fatal errors if the database has internal failures, thus rendering your application unusable.
I cannot understand this issue; if you encrypt/decrypt in php, you also need to store the values in the database with a database link? If the decryption fails on php's side, this also leads to application failures? What is the point made here?
- PHP can do the same MySQL decryption and encryption with some effort but without a database connection, which improves the application’s speed and efficiency.
Php can do it "with some effort" and that improves the application's speed? Because you're encrypting before it's sent over the wire, the application (which will handles the encryption) gains increased speed and efficiency? How could that be true? In my opinion, it's about the "best tool for the job", so the argument that "php is capable too" does not mean per se it's the best tool as well. It's just a tool, without the argument why it's the best tool.
- MySQL often logs transactions, so if the database’s server has been compromised, then the log file would produce both the encryption key and the original value.
This is a valid point if you encrypt values in the database and have logging turned on. At least you should turn off the general query log as the binary log does only log transactions but no select statements. If you don't need logging at all, you could just make the statement "if you use AES in MySQL, turn off all loggin". That sounds more valid to me than "if you want to use AES in MySQL, do it in php".
Can anyone explain to me why above points might be valid and why -in general- it is better to encrypt your data in your (php) application rather than in (My)SQL.