【发布时间】:2016-12-10 09:43:26
【问题描述】:
我正在测试如何使用 PHP 编码函数从编码数据中获取实际数据。编码后我无法获得原始数据。相反,我得到了一些特殊的 Unicode 字符...
我的代码如下。
$key = '28e336ac6c9423d946ba02d19c6a2632'; // Randomly generated key
$request_params = array(
'controller' => 'mylist',
'action' => 'read',
'username' => 'test',
'password' => '12345'
));
$enc_request = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, json_encode($request_params), MCRYPT_MODE_ECB));
//echo $enc_request;exit; // Here I am getting the encoded string.
$paramas = base64_decode(trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, json_decode($enc_request), MCRYPT_MODE_ECB)));
print_r($paramas); // Here I am getting like ... ºÇ
echo $paramas->controller; // Got nothing.
我做错了什么?
【问题讨论】:
-
解析错误:语法错误,第 8 行 tst.php 中出现意外的 ')'
-
修复:然后:
Notice: Trying to get property of non-object in tst.php on line 14 -
当我只尝试 var_dump($paramas);它让我... string(3) "ºÇ"...
标签: php json base64 mcrypt rijndael