Yii Framework Forum: Decrypt table data before/on search - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Decrypt table data before/on search

#1 User is offline   Sriram Panneerselvam 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 09-April 15
  • Location:Chennai, India

Posted 13 March 2018 - 06:11 AM

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

#2 User is offline   jim. 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 182
  • Joined: 28-June 12
  • Location:Germany

Posted 13 March 2018 - 06:44 AM

Did you try yii2-encrypter?

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


#3 User is offline   JFReyes 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 519
  • Joined: 28-October 09
  • Location:Puerto Rico

Posted 13 March 2018 - 08:16 AM

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.

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users