I am having a weird problem with a new model behavior I am trying to
implement. When I try to pass a value ($data) into the model behavior
function the passed value is replaced with the model object. The
passed value is a string before $this->enCrypt() is called, but within
the behavior function $data contains the model's object. Here is my
code:

Model:

        function save($data = null, $validate = true, $fieldList = array())
        {
                if(isset($data['Model']['field']) && $data['Model']['field'])
                {
                        $data['Model']['field'] = 
$this->enCryptCC($data['Model']
['field']);
                }

                return parent::save($data, $validate, $fieldList);
        }


Behavior:

class GlobalBehavior extends ModelBehavior {

        function enCrypt($data = null)
        {
            if ($data != null) {
            $td = mcrypt_module_open('cast-256', '', 'ecb', '');
            $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),
MCRYPT_RAND);
            mcrypt_generic_init($td, ENCRYPT_KEY, $iv);
            $encrypted_data = mcrypt_generic($td, $data);
            $encoded = base64_encode($encrypted_data);
            if (!mcrypt_generic_deinit($td) || !mcrypt_module_close
($td)) {
                $encoded = false;
            }
        } else {
            $encoded = false;
        }
        return $encoded;
    }

    function deCrypt($data = null)
    {
        if ($data != null) {
            $data = (string) base64_decode(trim($data));
            $td = mcrypt_module_open('cast-256', '', 'ecb', '');
            $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td),
MCRYPT_RAND);
            mcrypt_generic_init($td, ENCRYPT_KEY, $iv);
            $data = (string) trim(mdecrypt_generic($td, $data));
            if (!mcrypt_generic_deinit($td) || !mcrypt_module_close
($td)) {
                $data = false;
            }
        } else {
            $data = false;
        }
        return $data;
    }
}

Anybody have any ideas what is happening?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to