Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RSA解码(phpseclib)JSON字符串抛出错误3_Json_Phpseclib - Fatal编程技术网

RSA解码(phpseclib)JSON字符串抛出错误3

RSA解码(phpseclib)JSON字符串抛出错误3,json,phpseclib,Json,Phpseclib,我正在尝试解码通过RSA(PHPSECLIB)传输的JSON。这将抛出JSON\u错误\u CTRL\u字符 $json_string = $rsa->decode($cyphertext); $json_object = json_decode($json_string); $json_字符串看起来像 {\u0000\"\u0000k\u0000e\u0000y\u0000\"\u0000:\u0000\"\u0000W\u0000Z\u0000g\u0000... json_las

我正在尝试解码通过RSA(PHPSECLIB)传输的JSON。这将抛出JSON\u错误\u CTRL\u字符

$json_string = $rsa->decode($cyphertext);
$json_object = json_decode($json_string);
$json_字符串看起来像

{\u0000\"\u0000k\u0000e\u0000y\u0000\"\u0000:\u0000\"\u0000W\u0000Z\u0000g\u0000...
json_last_error()返回3

我做错了什么?

解决方案:

RSA解密将空字符放入消息中。你必须删除它们

$json_string = $rsa->decode($ciphertext);  //decode my message
$json_string = str_replace("\0", "", $json_string); //replace null chars with "null" :D
$json_object = json_decode($json_string);  //decode json_string

看起来您正在对UTF-16字符串进行编码,并尝试将其解码为US-ASCII或类似的格式。