首页 > Web开发 > 详细

php openssl

时间:2020-08-28 12:01:11      阅读:89      评论:0      收藏:0      [点我收藏+]

 

$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

 

php openssl

原文:https://www.cnblogs.com/cxscode/p/13576162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!