Answer the question
In order to leave comments, you need to log in
Email addresses in the database in encrypted form in PHP, how to implement?
Good day to all!
I've been developing in PHP for quite some time now, but I've worked very little with cryptography. And this is the task before me.
There is a `users` table in the MySQL database. The table has fields: `uid` - user id and `email` - user's e-mail address.
I need to write php (using only common php modules like Mcrypt) code that:
Answer the question
In order to leave comments, you need to log in
additional fields cannot be used
sprintf("%s_%s", base64_encode($encripted_domain), base64_encode($encripted_username));
sprintf("SELECT * FROM table WHERE email LIKE \"%s_%%\" ", base64_encode($encripted_domain));
list($domain_base64, $username_base64) = explode("_", $encripted_email_from_db);
$decripted_email = sprintf("%[email protected]%s", decript_function(base64_decode($username_base64)), decript_function(base64_decode($username_base64)));
https://dev.mysql.com/doc/refman/5.5/en/encryption... for example, you can encrypt inside the database.
Something like - INSERT INTO table VALUES (AES_ENCRYPT (email))
Select - SELECT AES_DECRYPT (email)
But for searching by domain, it is better to create a separate column.
Well, or you get a mega-long search, like WHERE AES_DECRYPT (email) LIKE '%domain'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question