1.生成公钥私钥 win下必须要openssl.cof支持 liunx一般已自带安装
直接上代码:
<?php
$config = array(
//"digest_alg" => "sha512",
"private_key_bits" => 512, //字节数 512 1024 2048 4096 等
"private_key_type" => OPENSSL_KEYTYPE_RSA, //加密类型
);
//创建公钥和私钥 返回资源
$res = openssl_pkey_new($config);
//从得到的资源中获取私钥 并把私钥赋给$<span style="font-family: Arial, Helvetica, sans-serif;">privKey</span>
openssl_pkey_export($res, $privKey);
//<span style="font-family: Arial, Helvetica, sans-serif;">从得到的资源中获取公钥 返回公钥 </span><span style="font-family: Arial, Helvetica, sans-serif;">$pubKey</span><span style="font-family: Arial, Helvetica, sans-serif;">
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
//var_dump($privKey);
//var_dump($pubKey);
var_dump(array('privKey'=>$privKey,'pubKey'=>$pubKey));
die;
?>
Comments | NOTHING