PHP 生成RSA公钥、私钥并加解密
|
字数总计:
510
|
阅读时长:
1分钟
|
阅读量:
14
这篇文章距离最后更新已过1661 天,如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
实现代码
$config = array(
"digest_alg" => "sha512",
"private_key_bits" => 1024, //字节数 512 1024 2048 4096 等
"private_key_type" => OPENSSL_KEYTYPE_RSA, //加密类型
);
$res = openssl_pkey_new($config);
$privKey = null;
openssl_pkey_export($res,$privKey,null,$config);
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey['key'];
openssl_private_encrypt($string,$encrypt_string,$privKey);
$encrypt_string = base64_encode($encrypt_string);
评论已关闭