I want to store the email addresses of users in a MySQL database using encryption to ensure that they won’t be made public if the database gets compromised. I believe if I encrypt them with mysql’s AES_ENCRYPT() function I can not create an index in an INNODB table because I have to use a BLOB datatype. If the table gets very large selects it will take a long time.
What is the best solution for securing email address but still being able to query them fast and preserve them as unique values in the column?
When a user registers on your site, use AES_ENCRYPT() to encrypt the email.
When you query your database, you can call the AES_DECRYPT() function like this: