json 字符串非对称加密问题
本帖最后由 gwrc_s_d_n 于 2013-08-12 10:20:07 编辑
最近又个项目,是需要在PHP里发送http请求的,并且要用非对称加密。其中需加密的部分是json字符串。
现在测试问题是,如果直接用公钥加密json串传到服务器端,就会解密失败(客户端测试加密再解密正常),如果base64_encode后再加密传服务器,就能解密成功(这样有点麻烦,json要base64一次,加密后又要base64一次)。
想问下,是本就不应该直接对json字符串加密呢?还是我发送HTTP请求有问题?是用http_client发的请求,直接用fsockopen也不行。
$data['username'] = 'test133ed';
$data['content'] = base64_encode(json_encode(array('brid' => '22228222883956', 'money' => 10000000, 'time' => time()))); //这里不用base64_encode的话,传过去就不能解密
openssl_sign($data['content'], $data['sign'], $privkey);
openssl_public_encrypt($data['sign'], $sign, $serverkey);
$data['sign'] = base64_encode($sign);
openssl_public_encrypt($data['content'], $data['content'], $serverkey);
$data['content'] = base64_encode($data['content']);
$pageContents = HttpClient::quickPost('http://www.test.t:80/index.php/agent/store', $data);
$result = explode(',', $pageContents);
print_r($result);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn