Tuesday, March 15, 2016

Storing encrypted value using getter/setter not working. Stored in plain text.

I am trying to save a string value in the database. this value needs to be encrypted. I tried to create a _set and _get function to encrypt/decrypt this. 

here is the code:

protected function _setUsername($username)
{
 $key
= 'wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA';
 
if(strlen($username) > 0)
 
{
 $username
= Security::encrypt($username, $key);
 
}
 
return($username);
}

protected function _getUsername($username)
{
 $key
= 'wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA';
 
if(strlen($username) > 0)
 
{
 $username
= Security::decrypt($username, $key);
 
}

 
return($username);
}


However the value is stored in plain text. Am I misunderstanding the documentation on the use of these functions?


--
Sign up for our Newsletter for updates.
http://cakephp.org/newsletter/signup
 
We will soon be closing this Google Group. But don't worry, we have something better coming. Stay tuned for an updated from the CakePHP Team soon.
 
Like Us on FaceBook https://www.facebook.com/CakePHP
Follow us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: