It was not given many details but by the described way I believe that is only encrypt what you want to look for, then the comparison will be made of the data encrypted with another data likewise encrypted.
$query = "select * from tabela where campo = " . crypt("BRASIL");
I put in the Github for future reference.
This may not work depending on some factors such as how encryption is done, database configuration for comparison (collation), etc. But I believe you are using a simple way and this way will work.
With LIKE
under normal conditions is not possible, at least I do not know a form. It may be possible with some additional module to Mysql but I don’t know any that do this. I don’t really 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 too much on this because it does not seem to be the best of ideas.
A horrible possible solution would be to take all the encrypted data, decrypt it in PHP and make the selection. It’s easier to do than the previous solution but terrifying to use.
I found that solution in the OS for cryptography builtin Mysql. I wouldn’t know to say all the limitations except the performance already mentioned there.
select * from tabela where aes_decrypt(campo, salt) like '%BRASIL%'
I put in the Github for future reference.
Obviously this only works if the data is recorded in the same way.
Behold other encryption functions builtin mysql.
Poise, however I need to use the LIKE and would not work this way.
– Vinícius Lara
Only you didn’t put it in the question.
– Maniero
Sorry, I omitted details, already arranged. I will read your reply.
– Vinícius Lara
That way it would only be possible with this kind of correct encryption?
– Vinícius Lara
Could be with any kind of encryption builtin.
– Maniero
I use a php function that encrypts with Base64 and keys
– Vinícius Lara
As I said, it would complicate a lot, I would have to use extremely complex solutions. Besides, Base64 doesn’t encrypt anything.
– Maniero
See, AES-256-CBC is the method the function uses
– Vinícius Lara
But it’s not the job builtin mysql. At least according to what you said.
– Maniero
Hi, I made my adaptations and came to a doubt, I am inserting now using mysql AES function, and then using TO_BASE64 to "fit" the code, I tried to use now
select * from tabela where FROM_BASE64(aes_decrypt(campo, salt)) like '%BRASIL%'
but it doesn’t work, because?– Vinícius Lara
I cannot say, there is not enough information http://answall.com/help/mcve. Note that this is already a different problem than you originally posted in the question.
– Maniero