RSA解码(phpseclib)JSON字符串抛出错误3
我正在尝试解码通过RSA(PHPSECLIB)传输的JSON。这将抛出JSON\u错误\u CTRL\u字符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
$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或类似的格式。