Search database with encrypted data

0

I have a database where the inserted data is encrypted through a function written in PHP, this function encrypts and decrypts. I need to search this table.

For example, I search for "BRAZIL", but in the table "BRAZIL" is encrypted as: cdlddzfqm3b3szyxvvk2u3n6lzb1ut09

Use PHP and MySQL, and to do the searches use LIKE % %

    
asked by anonymous 28.01.2015 / 16:40

1 answer

3

You have not given much detail but by the way described I believe that it is only to encrypt what you want to search, then the comparison will be made of the encrypted data with another encrypted data .

$query = "select * from tabela where campo = " . crypt("BRASIL");

This may not work depending on some factors such as how encryption is done, configuration of the database for collation, etc. But I believe you are using a simple form and this form will work.

With LIKE under normal conditions it is not possible, at least I do not know a form. It may be possible with some additional module to MySQL but I do not know anyone who does this. I really do not know if it's a good idea to do this.

It may be possible to create a function for MySQL (possibly in C) that can be used in place of or with LIKE to do this search. nor will I speculate much on this because it does not seem to be the best of ideas.

One possible horrible solution would be to get all the encrypted data, decrypt it in PHP and make the selection. It's easier to do than the earlier but gruesome solution to use.

I found this OS solution for MySQL encryption builtin . limitations except the performance already mentioned there.

select * from tabela where aes_decrypt(campo, salt) like '%BRASIL%'

Obviously this only works if the data is recorded in the same way.

See other encryption functions builtin of MySQL.

    
28.01.2015 / 16:45