使用的开发环境是PHPstudy ,在使用OpenSSL的函数openssl_pkey_new()时,始终返回false,检查了环境,OpenSSL扩展已经开启,代码如下:
$config = array(
'private_key_bits' => 2048,
);
$res = openssl_pkey_new($config);
$res返回false的时候,检查发现,是window系统缺少了openssl环境变量,解决方法如下:
$opensslConfigPath = "D:/phpStudy/Apache/conf/openssl.cnf"; //apache路径下的openssl.conf文件路径
$config = array(
'private_key_bits' => 2048,
);
$res = openssl_pkey_new($config);
if(!$res) {
$config['config'] = $opensslConfigPath;
$res = openssl_pkey_new($config);
}
修改之后运行,返回正常。