2 回答

TA貢獻1810條經驗 獲得超4個贊
好吧,這對我有用:
更改為 。openssl_pkey_export($res, $privKey);
openssl_pkey_export($res, $privKey, NULL, $config);

TA貢獻1856條經驗 獲得超5個贊
您不需要像這樣導出密鑰私有,至少在將其保存在安全的地方之前是這樣:
$config = array(
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA
);
$pki = openssl_pkey_new($config);
$public = openssl_pkey_get_public(
openssl_pkey_get_details($pki)['key']
); // why on earth did they implement it like this? so clunky.
$private = openssl_pkey_get_private($pki);
$data = 'Hello, World!';
openssl_public_encrypt($data, $encrypted, $public);
openssl_private_decrypt($encrypted, $decrypted, $private);
var_dump(
bin2hex($encrypted),
$decrypted
);
- 2 回答
- 0 關注
- 565 瀏覽
添加回答
舉報