Codeigniter AES解码显示奇怪的字符

时间:2012-10-14 22:02:30

标签: codeigniter aes decode encode

我尝试了:

$data = array('ip'=>'120.0.3.4','user'=>'robert');

 $this->load->library('encrypt');
    $this->encrypt->set_cipher(MCRYPT_RIJNDAEL_256);
    $this->encrypt->set_mode(MCRYPT_MODE_ECB);
    $key = random_string();
    $o=$this->encrypt->encode($data,$key);
var_dump($o);
$this->encrypt->set_cipher(MCRYPT_RIJNDAEL_256);
    $this->encrypt->set_mode(MCRYPT_MODE_ECB);
    $o = $this->encrypt->decode($o,$key);
    var_dump($o);

它解码了奇怪的字符:

string(44) "CVwMzZGkzagW4wHbUZfNpVWACQp2Fx4TeAO2KLqZs3I=" string(32) "��pz��xJx�jʊ8�Kw��mS�Y �1�_�" 

任何建议?

这是由阵列加密引起的吗?我需要按值加密值而不是加密所有数组以使用加密数据的数组? THX

1 个答案:

答案 0 :(得分:2)

您正在将数组传递到$this->encrypt->encode()encode()方法采用字符串。请参阅Encryption Class

如果启用了PHP错误,您还会看到:

A PHP Error was encountered
Severity: Warning
Message: mcrypt_encrypt() expects parameter 3 to be string, array given
Filename: libraries/Encrypt.php

Turn PHP errors on在您的开发机器上捕捉这些。