$config = [ ‘digest_alg‘ => ‘sha256‘, ‘private_key_bits‘ => ‘512‘, ‘pricate_key_type‘ => OPENSSL_KEYTYPE_RSA, ]; $res = openssl_pkey_new($config); openssl_pkey_export($res, $rsaPrivKey); $pubKey = openssl_pkey_get_details($res); $rsaPubKey = $pubKey[‘key‘];
这样便可获取生成的公钥$rsaPubKey和私钥$rsaPrivKey
问题一:
$res返回false的时候,检查发现,是window系统缺少了openssl环境变量,解决方法如下:
第一种是给传入的$config添加‘config‘值,对应php下openssl.cnf的文件地址
$config[‘config‘] = ‘D:\bin\php\extras\ssl\openssl.cnf‘;
openssl_pkey_export 的 $configargs 也要传下,不然会返回null
https://www.cnblogs.com/andydao/p/10365031.html
https://zhidao.baidu.com/question/1797682641931562907.html
https://www.cnblogs.com/wadhf/p/12041267.html