I have a huge database with non encrypted fields.
These data are sensitive and the managers took a decision to encrypt them as soon as we can. And all new data should be automatically encrypted to the same way.
First Method:
If I use aes_encrypt
to create a new field and insert the encrypted data to it like the following:
INSERT INTO myTable(name_en, name_es, phone)
VALUES(aes_encrypt(name_en, :key), aes_encrypt(name_es, :key), aes_encrypt(phone, :key))
And afterwards, each insert query should use aes_encrypt()
, it will be resourceful to the server.
Second method:
Use libsodium
library, which is a great solution to the new data. But the exisiting data will stay the same as libsodium couldn't be used inside a MySQL Query.
Third Method:
Using mcrypt_encrypt with MCRYPT_RIJNDAEL_128 as an equivalent to aes_encrypt
, and then insert the encrypted variable into the query without letting MySQL do the encryption part, which will reduce loads and processing time.
But the mcrypt_encrypt
isn't secure anymore, specially with the ECB
mode.
What is the best method, to encrypt few fields in an exisiting MySQL database, and of course, the new one ? And if I used mcrypt with mode CFB, can use aes_decrypt afterwards to check the data ?