Yii Framework Forum: CSecurityManager not decrypting correctly - Yii Framework Forum

Jump to content

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

CSecurityManager not decrypting correctly Rate Topic: -----

#1 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 18 February 2010 - 05:02 PM

Hi,

I'm not getting the results I expect from CSecurityManager. I'm using it like this...

Yii::app()->getSecurityManager()->setEncryptionKey('secretkey');
$user = User::model()->find(1);
$user->test = Yii::app()->getSecurityManager()->encrypt('astring');
$user->save();


now when I retrieve the results I use this...
Yii::app()->getSecurityManager()->setEncryptionKey('secretkey');
$user = User::model()->find(1);
echo Yii::app()->getSecurityManager()->decrypt($user->test);


What i get back is gibberish i.e. encrypted text that does not match 'astring'. The column 'test' in my MySQL db is of BLOB datatype.

What's happening here that I'm not getting?
0

#2 User is offline   Daniel M 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 19-January 10
  • Location:Germany, Saarland

Posted 18 February 2010 - 08:33 PM

Hmn, looks like there goes something wrong between saving and loading the encrypted data.

Did you check if the encrypted string before saving is still similar with the string after loading?
Utinam ea res tibi usui fuerit!
0

#3 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 19 February 2010 - 01:23 PM

Well, I was playing about with this in work today and couldn't replicate the fault. So, I just checked my model and I had a beforeSave changing the variable to base64_encode hence it not working as expected! silly me.

Now that is sorted, is there a way to change cipher/mode etc? what is the default cipher/mode for this class?
0

#4 User is offline   MD311 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-March 10
  • Location:Georgia

Posted 04 March 2010 - 09:47 PM

Take a look at yii/framework/base/CSecurityManager.php
I believe that it is 3DES and CBC mode. I have changed mine to RIJNDAEL_256 with ECB mode, so I don't recall the original settings.
0

#5 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 04 March 2010 - 10:46 PM

comment the if your table is not utf8, comment the line from your config that sets charset to utf8. also make sure the field length in your table is large enough to store the encrypted value.

I remember experiencing the same problem a while back.
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
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