本篇文章給大家帶來的內容是關于php如何生成公鑰私鑰(代碼),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。
//http://www.lampol-blog.com/detail/aid/ZDk5MmFNZ2pJL1pROW5QZU9KZ2FWdVlFTDVHRnRmZm4rNDMzSFlHNg%3D%3D 各種秘鑰生成的教程
//生成密鑰
$opensslConfigPath = "D:\phpstudy\PHPTutorial\Apache\conf\openssl.cnf";
$config = array(
"digest_alg" => "sha512",
"private_key_bits" =>2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
'config'=> $opensslConfigPath
);
//創建密鑰對
$res = openssl_pkey_new($config);
//生成私鑰
openssl_pkey_export($res, $privkey, null, $config);
//生成公鑰
$pubKey = openssl_pkey_get_details($res)['key'];
print_r($privkey);
echo '
1
';print_r($pubKey);
file_put_contents('private.key',$privkey);
file_put_contents('public.key',$pubKey);
?>
相關推薦: