Vicky
Vicky

Reputation: 941

how to use Like statement to get encrypted value from a table in mysql?

how to use like statement in encrypted column in mysql

i need to get user id from a table where username is like some value(user given input). but my username column is locally encrypted and stored in DB. Now, how to get the decrypt value from DB for using like statement. i am using Like statement in search method to get the values from the table that matches it, but values are encrypted in table.

For example: vi - 68726rgur4746r279267(encrypted type first name in db).

when i type vi in the search box everything that starts with word vi should be taken from the db.

Upvotes: 1

Views: 1860

Answers (1)

Abhishek Sharma
Abhishek Sharma

Reputation: 6661

You can't search on an encrypted column without first decrypting it.

Select * From table
WHERE AES_DECRYPT(col_name,key_str) LIKE '%something%'

Upvotes: 1

Related Questions