cakephp 2.8保持数据库中的加密数据不起作用

时间:2016-05-24 09:41:28

标签: mysql cakephp encryption

我必须以加密形式保留问题表的2个字段(questionoptions

core.php中

Configure::write('Security.ekey', '1234567890~`!@#$%^&*()_+-={}[]<>,./?qwertrpoiuytlkskhsffgzxmnxcbvLAKSJHFJPOQWUTERLKDJAD');

Question模式中我有

public $encryptedFields = array('question', 'options');
public function beforeSave($options = array()) {    
        foreach($this->encryptedFields as $fieldName){
            if(!empty($this->data[$this->alias][$fieldName])){
                $this->data[$this->alias][$fieldName] = Security::rijndael(
                        $this->data[$this->alias][$fieldName],
                        Configure::read('Security.ekey'), 'encrypt');
            }
        }
        return true;
    }

 public function afterFind($results, $primary = false) {
     //debug($results); this return nothing while data is being displayed having question and option fields null
    foreach($this->encryptedFields as $fieldName){
        if(!empty($results[$this->alias][$fieldName])){
            $results[$this->alias][$fieldName] = Security::rijndael(
                    $results[$this->alias][$fieldName], 
                    Configure::read('Security.ekey'), 'decrypt');
        }
    }
    return $results;
}

我搜索了不同的博客和stackoverflow问题 还尝试将字段的数据类型更改为(text,blob,longblob) 这些字段的长度可能很长(与text数据类型相同)请同时建议哪种数据类型最好保留其加密字符串。

0 个答案:

没有答案