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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Willem
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Willem
When I try as follows, the value gets stored encryted, but I cannot read it as the getDecryptedUsername function returns false at the decrypt line:

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

protected function _getDecryptedUsername()
{
 $key
= 'wt1U5MACWJFTXGenFoZoiLwQGrLgdbHA';
 $username
= $this->_properties['username'];
 
if(strlen($username) > 0)
 
{
 $username
= Security::decrypt($username, $key);
 
}
 
return($username);
}

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Willem
In reply to this post by Willem
saving to the database cuts off the encrypted data. varchar(255) and text fields both have this issue.. 
is this a bug in CakePHP

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Christian Quispe-2
Cambia tu field de tu base de datos a text, es posible que tu cadena codificada no se guarde completamente.



Enviado con MailTrack

Saludos

Christian Quispe

Geek and Developer
Miembro:  GDG Lima (Google Developer Group Lima)

Portafolio: www.oxicode.io

¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...


2016-03-15 13:46 GMT-05:00 Willem <[hidden email]>:
saving to the database cuts off the encrypted data. varchar(255) and text fields both have this issue.. 
is this a bug in CakePHP

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Willem
I have already tried to change it to text. This had the same effect. I also cleared the caches/orm cAche when intested this. 



Op 16 mrt. 2016 om 00:12 heeft Christian Quispe <[hidden email]> het volgende geschreven:

Cambia tu field de tu base de datos a text, es posible que tu cadena codificada no se guarde completamente.



Enviado con MailTrack

Saludos

Christian Quispe

Geek and Developer
Miembro:  GDG Lima (Google Developer Group Lima)

Portafolio: www.oxicode.io

¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...


2016-03-15 13:46 GMT-05:00 Willem <[hidden email]>:
saving to the database cuts off the encrypted data. varchar(255) and text fields both have this issue.. 
is this a bug in CakePHP

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

heavyKevy
In reply to this post by Willem
I hate to state the obvious, but did you verify that the field size was large enough to store the encrypted value?
I had a similar issue with hashing a password, the field wasn't large enough and the value was saved but cut off so that the password never matched.
Maybe try it with the max varchar size and see if it will work.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Willem
Eventually i changed it to a varbinary(65000) column and it started to work. In Cakephp 2 it worked with a varchar column. now it needs to be binary in 3 and have enough space.

On Wednesday, March 16, 2016 at 10:19:38 AM UTC+1, heavyKevy wrote:
I hate to state the obvious, but did you verify that the field size was large enough to store the encrypted value?
I had a similar issue with hashing a password, the field wasn't large enough and the value was saved but cut off so that the password never matched.
Maybe try it with the max varchar size and see if it will work.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.