PHP openssl生成Rsa秘钥对

#   PHP openssl生成Rsa秘钥对



<?php
$config = array(
	"config"=>"D:/WebServer/php-5.6.35-nts-Win32-VC11-x64/extras/ssl/openssl.cnf",
	"digest_alg"    => "sha512",
	"private_key_bits" => 4096,           //字节数  512 1024 2048  4096 等 ,不能加引号,此处长度与加密的字符串长度有关系,可以自己测试一下
	"private_key_type" => OPENSSL_KEYTYPE_RSA,   //加密类型
);
//创建公钥和私钥   返回资源
$res = openssl_pkey_new($config);
//从得到的资源中获取私钥,把私钥赋给$privKey
openssl_pkey_export($res, $privKey, null, $config);
//从得到的资源中获取公钥,返回公钥$pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
 
echo '<pre>';
echo $privKey,$pubKey;


# xiaoxiao [ 2022-05-12 ]

# Address in this article

# http://www.s7smile.com/php/51

# s7smile.com