Decrypt table data before/on search

Hi folks,

I am using Yii2. I have encypted some fields before store into database using beforesave function in model.

I could not get results from database, if user searched based on input.

I mean how can decrypt database value while finding data? I tried beforefind() also.

Thanks in advance

Did you try yii2-encrypter?

This module has a behavior which can be attached to your activerecord:

I had the same problem as the OP even with yii2-encrypter. AFAIK the problem cannot be resolved with the current framework as it stands because the clause andFilterWhere() in the Search class query doesn’t encrypt the user input so it can be compared effectively with the encrypted column in the database using %LIKE%. It is worse for a partial match because even if it could be encrypted, the result would never match what’s in the database.

A possible workaround is to use an ArrayDataProvider or a SQLDataProvider to load up the encrypted data in memory and then apply the decryption, but I could not get it to work. I turned to whole database encryption instead.

I requested that this be improved in Yii 2.1; let’s see if it happens. Good luck.