Yii Framework Forum: Encryption - Yii Framework Forum

Jump to content

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

Encryption Rate Topic: -----

#1 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 14 June 2013 - 05:07 AM

I have already data in a database that is not encrypted. Now I have decided that some of the data should be encrypted and I thought the best way to do it is to use CSecurityManager. How can I encrypt the already existing data in database?
0

#2 User is offline   JFReyes 

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

Posted 14 June 2013 - 12:24 PM

Try moving the unencrypted data attribute to a temporary variable; next encrypt that temporary variable; then save the encrypted result into the original data attribute. Be careful that the column definition supports the encrypted value (size, charset, etc.).
José
0

#3 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 02:50 AM

Hi, Thank you for the reply. What should the size and charset be, if I use CSecurityManager?
0

#4 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 03:24 AM

There is said in CSecurityManager documentation that "PHP Mcrypt extension must be installed and loaded". How do I do that?
0

#5 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 04:20 AM

I'm trying to encrypt the name in beforeSave function in my model, but it doesn't encrypt. What might be the problem?
public function beforeSave()
    {
        Yii::app()->getSecurityManager()->encrypt($this->name); 
                                
        return parent::beforeSave();
    } 

0

#6 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 04:26 AM

View Posthelju, on 17 June 2013 - 04:20 AM, said:

I'm trying to encrypt the name in beforeSave function in my model, but it doesn't encrypt. What might be the problem?
public function beforeSave()
    {
        Yii::app()->getSecurityManager()->encrypt($this->name); 
                                
        return parent::beforeSave();
    } 



Ok, I found the problem. It should be

$this->name = Yii::app()->getSecurityManager()->encrypt($this->name);

0

#7 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 05:04 AM

Why do I get an empty string when I use this

 public function afterFind()
    {

        $eKey = Yii::app()->getSecurityManager()->getEncryptionKey();
       
        $this->name = Yii::app()->getSecurityManager()->decrypt($this->name, $eKey); 
        
        return parent::afterFind();
    }

0

#8 User is offline   helju 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 20
  • Joined: 23-May 13

Posted 17 June 2013 - 05:47 AM

Ok, this seemed to do the trick. I changed in database the character set to UTF8 of name field and used these in my model class:


 public function afterFind()
    {

        $eKey = Yii::app()->getSecurityManager()->getEncryptionKey();
       
        $this->name = Yii::app()->getSecurityManager()->decrypt(utf8_decode($this->name), $eKey); 
        
        return parent::afterFind();
    }

    public function beforeSave()
    {
        
        $eKey = Yii::app()->getSecurityManager()->getEncryptionKey();

        $this->name = utf8_encode(Yii::app()->getSecurityManager()->encrypt($this->name, $eKey)); 
                                
        return parent::beforeSave();
    } 


and in main.php this



 'components' => array(
        
        'securityManager'=>array(
            'cryptAlgorithm' => 'blowfish',
            'encryptionKey' => 'Put here your secret key',
        ),


0

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