WHERE ('lastname' LIKE '%whatever the user entered and you decrypted%)
and what you want is:
WHERE ('decrypted column value' LIKE '%whatever the user entered in cleartext%)
Getting that decrypted column value is the problem. I’ve tried:
using a stored procedure. It works by itself but MySQL won’t accept a CALL command in the WHERE clause;
MySQL also doesn’t like a dbExpression such as (AES_DECRYPT(FROM_BASE64(‘column’)) on the WHERE clause;
looked into MySQL’s (5.7.6+) generated virtual columns with the above expression but couldn’t get it to work;
I read that using FindAll() along with an ArrayDataprovider (instead of ActiveDataProvider) would work but didn’t see any sample code that would point me in the right direction.
Note that you have to call "decrypt" method for each and every data.
Both encryption and decryption are very time consuming job. While the former sample only execute encrypt() one time, the latter need to call decrypt() as many times as there are many data. The more there are data to be processed, the more time you have to spend.
Also the sorting requires that all the data be fully decrypted beforehand.
Thank you for the prompt reply, @softark. I realize that for searching/sorting inside a GridView I would need the data already decrypted. Perhaps my best bet would be using a SqlDataProvider where I can decrypt it using SQL. Another approach I’ll look into is the generated virtual column available in MySQL 5.7.6+. I’ll post back after my trials.
Thank you for the guidance, @softark; your code makes sense. I’ll take a look at the possible complications you mentioned because it seems that it will consume a lot of resources (CPU/RAM) and I don’t know yet the size of the data set.