openssl_pkey_new在xampp中不起作用

时间:2017-05-13 19:12:49

标签: php encryption public-key-encryption php-openssl

我已经谷歌搜索并研究了openssl好几天了,并且还没有在XAMPP for windows中找到openssl_pkey_new问题的解决方案。试过这两个版本。 7.1.1和7.1.4。每次我尝试运行此代码:

echo getenv('OPENSSL_CONF')."<p>";

$config = array(
    "config" => "c:/xampp/apache/conf/openssl.cnf",
    "digest_alg" => "sha256",
    "private_key_bits" => 4096,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
);

// Create the private and public key
$res = openssl_pkey_new($config);
echo "<br>openssl_pkey_new: <br>";
//var_dump(openssl_error_string());
while($e = openssl_error_string() ) {
    print_r($e."<br>\n");
}

// Extract the private key from $res to $privKey
openssl_pkey_export($res, $privKey);
echo "<br>openssl_pkey_export: <br>";
while($e = openssl_error_string() ) {
    print_r($e."<br>\n");
}

// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
echo "<br>openssl_pkey_get_details: <br>";
while($e = openssl_error_string() ) {
    print_r($e."<br>\n");
}

我收到这些错误:

openssl_pkey_new:
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:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value
error:0E06D06C:configuration file routines:NCONF_get_string:no value

openssl_pkey_export:
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.cnf或/和server.key + server.csr + server.crt 和/或可能是错误的libeay32.dll + ssleay32.dll,还是一切都不好? 一个令人讨厌的问题,在我的表达中要温和!!

密钥生成教程: https://latunyj.wordpress.com/2011/10/31/generating-self-signed-certificate-in-xampp-win32-for-apache-web-server/

问题的全面答案: What I have to do to OpenSSL extension work on my xampp (Windows)? :(

其他链接: https://snippets.aktagon.com/snippets/543-how-to-fix-pem-read-bio-no-start-line-error-nginx-error http://au.php.net/manual/en/openssl.installation.php https://community.apachefriends.org/f/viewtopic.php?f=16&t=71199

真的希望有人知道这个问题的答案。

编辑:

如果想知道为什么它很烦人,是因为我在服务器和客户端之间使用RSA-OAEP,实现openssl和webcrypto来加密/解密AES-CBC密钥。 AES-CBC加密数据与加密密钥一起交换。

我的临时解决方法是在客户端上生成在服务器上重新发送RSA密钥对并以明文形式发送。好的开发,但不适合生产。那是烦人的部分。 7.x.x之前的XAMPP没有AES-CBC方法。顺便说一句XAMPP只是发展。

0 个答案:

没有答案