>  기사  >  백엔드 개발  >  json 字符串非对称加密有关问题

json 字符串非对称加密有关问题

WBOY
WBOY원래의
2016-06-13 12:39:51926검색

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);
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.