问题:OpenSSL是不是在我的Windows环境下工作。 OpenSSL的多次报告错误0x02001003,0x2006D080和0x0E064002。
环境:
Windows NT x 6.1 build 7601 (Windows 7 Business Edition Service Pack 1) i586
Apache/2.4.4 (Win32)
PHP/5.4.13 x86
PHP Directory: E:\wamp\php\
Virtual Host Directory: E:\Projects\1\public_html
我已经尝试:
- 安装说明 http://www.php.net/manual/en/openssl.installation.php
- php.ini中
extension=php_openssl.dll
- openssl.cnf中
E:\wamp\php\extras\openssl.cnf
- %PATH%
E:\wamp\php
- 重新启动
- 的phpinfo:
----启用OpenSSL的支持
---- OpenSSL库版本的OpenSSL 1.0.1e 2013年2月11日
---- OpenSSL的头版本的OpenSSL 0.9.8y 2013年2月5日 - 有和没有在指定配置
configargs
- 具有和不具有指定
<Directory E:\wamp\php\extras>
在apache配置 - 复制
openssl.cnf
,以虚拟主机的public_html,指出了,仍然得到同样的错误 - 没有登录的error_log
- 研究:我花了最后2天研究这个,惊讶的还有它没有更多,所以我在这里发帖。 似乎与OpenSSL的配置或Apache / PHP无法正常读取配置问题。
码:
$privateKey = openssl_pkey_new();
while($message = openssl_error_string()){
echo $message.'<br />'.PHP_EOL;
}
结果:
error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib
error:02001003:system library:fopen:No such process
error:2006D080:BIO routines:BIO_new_file:no such file
error:0E064002:configuration file routines:CONF_load:system lib
OpenSSL的手动:
E:\wamp\apache\bin>openssl.exe pkey
WARNING: can't open config file: c:/openssl-1.0.1e/ssl/openssl.cnf
E:\wamp\apache\bin>set OPENSSL_CONF="E:\wamp\php\extras\openssl.cnf"
E:\wamp\apache\bin>openssl.exe pkey
3484:error:0200107B:system library:fopen:Unknown error:.\crypto\bio\bss_file.c:169:fopen('"E:\wamp\php\extras\openssl.cnf"','rb')
3484:error:2006D002:BIO routines:BIO_new_file:system lib:.\crypto\bio\bss_file.c:174:
3484:error:0E078002:configuration file routines:DEF_LOAD:system lib:.\crypto\conf\conf_def.c:199:
编辑:
- 由于@Gordon我现在可以用看open_ssl错误
openssl_error_string
- 完全卸载的EasyPHP。 手动安装PHP / Apache的稳定版本。 同样的结果! 绝对的东西,我做错了在Windows上实现的OpenSSL。
- OpenSSL的手动节...其他错误信息
最后的想法:
我成立了一个Linux操作系统中,我得到了同样的错误。 一些上场后,我周围看到,即使它在openssl_pkey_new引发错误它最终创建我的测试P12文件。 长话短说,错误是误导性的,它必须处理更多的与您如何使用OpenSSL的功能没有那么多的服务器端配置。
最终代码:
// Create the keypair
$res=openssl_pkey_new();
// Get private key
openssl_pkey_export($res, $privkey);
// Get public key
$pubkey=openssl_pkey_get_details($res);
$pubkey=$pubkey["key"];
// Actual file
$Private_Key = null;
$Unsigned_Cert = openssl_csr_new($Info,$Private_Key,$Configs);
$Signed_Cert = openssl_csr_sign($Unsigned_Cert,null,$Private_Key,365,$Configs);
openssl_pkcs12_export_to_file($Signed_Cert,"test.p12",$Private_Key,"123456");
很近。
一年后...
所以,我发现自己在一年后,也不管我在电脑上或脚本执行过程中设置任何PATH变量再次这样做,不停地示数约未找到文件。 我能够通过传递来解决它config
的参数config_args
阵列openssl_pkey_new
。 下面是测试成功使用OpenSSL的能力的功能:
/**
* Tests the ability to 1) create pub/priv key pair 2) extract pub/priv keys 3) encrypt plaintext using keys 4) decrypt using keys
*
* @return boolean|string False if fails, string if success
*/
function testOpenSSL($opensslConfigPath = NULL)
{
if ($opensslConfigPath == NULL)
{
$opensslConfigPath = "E:/Services/Apache/httpd-2.4.9-win32-VC11/conf/openssl.cnf";
}
$config = array(
"config" => $opensslConfigPath,
"digest_alg" => "sha512",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
$res = openssl_pkey_new($config); // <-- CONFIG ARRAY
if (empty($res)) {return false;}
// Extract the private key from $res to $privKey
openssl_pkey_export($res, $privKey, NULL, $config); // <-- CONFIG ARRAY
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
if ($pubKey === FALSE){return false;}
$pubKey = $pubKey["key"];
$data = 'plaintext data goes here';
// Encrypt the data to $encrypted using the public key
$res = openssl_public_encrypt($data, $encrypted, $pubKey);
if ($res === FALSE){return false;}
// Decrypt the data using the private key and store the results in $decrypted
$res = openssl_private_decrypt($encrypted, $decrypted, $privKey);
if ($res === FALSE){return false;}
return $decrypted;
}
// Example usage:
$res = testOpenSSL();
if ($res === FALSE)
{
echo "<span style='background-color: red;'>Fail</span>";
} else {
echo "<span style='background-color: green;'>Pass: ".$res."</span>";
}