I'm building a website and am trying to figure out a way to encrypt the user's email addresses. It would be nice if, in case my database was stolen, the emails of my users weren't in plain text. I figured the user needs the email to login obviously, so if I encrypt it with their password as the key, or even the email itself, then I could still build a login function, that would work.
Problem comes with situation when I need the user's email address. For example, in a situation as a password reset or sending out a newsletter. I could have a second field in the database with the user's email address, encrypted with a key that I know.
Can I encrypt something, where two keys work? Like a master key..... or am I being stupid?
AES_ENCRYPT()on MySQL/MariaDB is that, when encrypting the login field ("the user needs the email to login") then to read/verify it you need to decrypt the entire table and the more users you have the longer that takes. If you're going to encrypt the email address, you're better off using something else (like a plaint text username) to be the login field.