欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php如何生成公钥私钥(代码)

程序员文章站 2022-03-08 23:41:28
...

本篇文章给大家带来的内容是关于php如何生成公钥私钥(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。


<?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 '<p style="height:100px;background:red">1</p>';
print_r($pubKey);
file_put_contents('private.key',$privkey);
file_put_contents('public.key',$pubKey);
?>

相关推荐:

php rsa怎么生成公钥和私钥

PHP利用公钥私钥进行高强度加密

以上就是php如何生成公钥私钥(代码)的详细内容,更多请关注其它相关文章!

相关标签: 公钥私钥