0

私は公開鍵で暗号化してからエンコードされた文字列を持っています.200文字のようなものです。

SENDER:
$pubkey = file_get_contents('http://localhost/test/key.pub');
openssl_public_encrypt('hello world', $encrypted, $pubkey);
$first = $encrypted;
$url = 'http://localhost/demo_project/bank/?secure='.urlencode($first);
echo file_get_contents($url);

RECIEVER:
var_dump($_GET);

出力:

array(1) { ["secure"]=> string(0) "" }

安全なのはsecure=Qq%B8%143%F5%D1%15%C4%18%95g%D6%D0%2F%2CH%25%F8%A8%17%EF%2Bl%80%3Bc%9E%F2%9A%FB%CF3%EDj%B7%26%0F%A0%5E%1DM%AB%07%1Db%0F%C3%9E%A1%FF%82%7D%E50%15Vc%08t%0F%07%0Ag

最も奇妙なことは、 の場合はsecure=Qq%Bすべて正常に動作しますが、 の場合secure=Qq%B8は問題があるということです。

ここのようにcurlでも試してみましたが、うまくいきませんでした。誰かが私のエラーを指摘し、解決策を提案してくれますか?

4

1 に答える 1

0

base64 エンコーディングは、バイナリ データが 8 ビット クリーンではないトランスポート レイヤーを介したトランスポートに耐えられるように設計されています

openssl_public_encrypt() のバイナリ出力データをエンコードする必要があります。

送信者:

$pubkey = file_get_contents('http://localhost/test/key.pub');
openssl_public_encrypt('hello world', $encrypted, $pubkey);
$first = base64_encode($encrypted);
$url = 'http://localhost/demo_project/bank/?secure='.urlencode($first);
echo file_get_contents($url);

レシーバー:

var_dump($_GET);
$secure = base64_decode($_GET['secure']);

私は使用しますPOST

$url = 'http://localhost/demo_project/bank/';
$postdata = array("secure" => $first);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata) );
echo $response = curl_exec($ch);

curl_close($ch);
于 2013-05-07T12:06:51.250 に答える