CakePHP 2.0安全::未保存密码结果

CakePHP 2.0安全::未保存密码结果,cakephp,Cakephp,我试图在我的模型的beforeSave方法中加密一些数据。但它并没有被拯救 $currentBalance = $this->find("all", array( "fields" => array( "SUM(base_amount) as 'CurrentBalance'" ), "conditions" => array(

我试图在我的模型的beforeSave方法中加密一些数据。但它并没有被拯救

       $currentBalance = $this->find("all", array(
            "fields" => array(
                "SUM(base_amount) as 'CurrentBalance'"
            ),
            "conditions" => array(
                "Payment.user_id" => $this->data["Payment"]["user_id"]
            )
        ));

        $this->log($this->data["Payment"]);
        $this->log(Configure::read("Security.salt"));        
        $this->log(Security::cipher(implode("|", $this->data["Payment"]), Configure::read("Security.cipherSeed")));

        $this->set("balance", $currentBalance[0][0]["CurrentBalance"] + $this->data["Payment"]["base_amount"]);
        $this->set("balance_checksum", Security::cipher(implode("|", $this->data["Payment"]), Configure::read("Security.salt")));
如果我看一下日志文件,我会得到一些加密的数据,但这些数据都是乱七八糟的

而在数据库里,我什么也得不到

如果我用一个简单的字符串替换密码函数,比如说“123”。。。这是正确保存的

我已经确保数据库连接是utf8编码的,并且数据库中的字段具有utf8排序规则

任何关于这方面的建议都很好


谢谢

我遇到了一个类似的问题。问题是加密数据会产生一些无效的utf8字符。比如汉字之类的。我所做的是将加密字符串转换为十六进制,然后保存。当你把数据拿回来的时候,你把六边形解码成字符,然后破译它

(在AppModel.php中)


(在AppController.php中)decrypt方法,其中$this->CipherKey以与模型完全相同的方式加载到_构造中

<?php function __construct(){
$this->CipherKey = Configure::read('Security.cipherSeed');
}

/**
 * The main decrypting function
 * 
 * @param string $strToDecrypt the string to be decrypted
 * @return string the decrypted string 
 */
public function decryptCipher($strToDecrypt) {
    return Security::cipher(pack("H*", $strToDecrypt), $this->CipherKey);
}
?>

我遇到了一个类似的问题。问题是加密数据会产生一些无效的utf8字符。比如汉字之类的。我所做的是将加密字符串转换为十六进制,然后保存。当你把数据拿回来的时候,你把六边形解码成字符,然后破译它

(在AppModel.php中)


(在AppController.php中)decrypt方法,其中$this->CipherKey以与模型完全相同的方式加载到_构造中

<?php function __construct(){
$this->CipherKey = Configure::read('Security.cipherSeed');
}

/**
 * The main decrypting function
 * 
 * @param string $strToDecrypt the string to be decrypted
 * @return string the decrypted string 
 */
public function decryptCipher($strToDecrypt) {
    return Security::cipher(pack("H*", $strToDecrypt), $this->CipherKey);
}
?>