openssl_pkey_export和“无法从参数1获取密钥" [英] openssl_pkey_export and "cannot get key from parameter 1"
问题描述
我需要在我的php项目中使用openssl,因此我使用openssl创建了一个测试php页面.但是,我不断收到这些错误,我不确定为什么. openssl已启用.
I need to use openssl within my php project, so I created a test php page using openssl. However, I keep getting these errors and I am not sure why. openssl is enabled.
警告:openssl_pkey_export()[function.openssl-pkey-export]:无法从第18行的C:\ wamp \ www \ opensslsample \ index.php中的参数1获取密钥
Warning: openssl_pkey_export() [function.openssl-pkey-export]: cannot get key from parameter 1 in C:\wamp\www\opensslsample\index.php on line 18
警告:openssl_pkey_get_details()期望参数1为资源,在第21行的C:\ wamp \ www \ opensslsample \ index.php中给出布尔值
Warning: openssl_pkey_get_details() expects parameter 1 to be resource, boolean given in C:\wamp\www\opensslsample\index.php on line 21
<?php
//echo phpinfo();
$privateKey = openssl_pkey_new(array(
'private_key_bits' => 1024,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
));
openssl_pkey_export($privateKey, $privkey,"123");
$pubkey=openssl_pkey_get_details($privateKey);
$pubkey=$pubkey["key"];
?>
推荐答案
如果您在Windows上,这可能会有所帮助:
This may help if you are on windows:
- 点击开始"按钮
- 单击控制面板
- 单击系统和安全性
- 点击SYSTEM
- 单击高级系统设置
- 单击环境变量
- 在系统变量"下,单击新建"
- 输入变量名" OPENSSL_CONF
- 输入变量值".我是-C:\ wamp \ bin \ apache \ Apache2.2.17 \ conf \ openssl.cnf
- 单击确定"并关闭所有窗口,然后重新启动计算机.
- Click on the START button
- Click on CONTROL PANEL
- Click on SYSTEM AND SECURITY
- Click on SYSTEM
- Click on ADVANCED SYSTEM SETTINGS
- Click on ENVIRONMENT VARIABLES
- Under "System Variables" click on "NEW"
- Enter the "Variable name" OPENSSL_CONF
- Enter the "Variable value". My is - C:\wamp\bin\apache\Apache2.2.17\conf\openssl.cnf
- Click "OK" and close all the windows and RESTART your computer.
OPENSSL应该可以正常工作.
The OPENSSL should be correctly working.
这篇关于openssl_pkey_export和“无法从参数1获取密钥"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!