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 关注
- 571 浏览
添加回答
举报