views:

38

answers:

1

Hey,

I was just wondering how to decrypt/encrypt form data in cakephp by creating a behavior?

What I have so far:

$key = Configure::read('Security.cipherSeed'); Security::cipher($encrypt,$key)

debug($key);

function encrypt { var $autoEncrypt= 'true';}

function decrypt {}

Other than this I really could use some help.

+1  A: 

It's not really clear what you're asking... you provided some code; is it working? Is it not working? What happens when you try to use it? Are there error messages? If so, what are they?

A shot in the dark anyway: have you considered using automatic decryption?

<?php 
class User extends AppModel
{
  var $name = 'User';

  var $actsAs = array('Cipher' => array('autoDecypt' => true));
}
?> 

There is a lot of info on the cipher-behavior here: http://bakery.cakephp.org/articles/view/cipher-behavior

stormdrain
Oh why thank you. I was trying to stay away from not using any pear/out side scripts. Mainly I was just trying to use the built in cipher within cakephp.I guess my question was how do I exactly take a form and encrypt/decrypt the data in a behaiour.
Louis Stephens
Just use the `cipher` method of the Security class: http://api.cakephp.org/class/security#method-Securitycipher. Use `cipher('text','key');` in the model method that inserts the data, and do the same in the model method that retrieves the data.
stormdrain