问题描述
(这个问题最初发布在 ServerFault 上 - 我已将其删除并移至此处.)
我有一台运行 PHP 5.3.5 的开发机器和一台运行 PHP 5.3.8 的生产机器.
I have a development machine running PHP 5.3.5 and a production machine running PHP 5.3.8.
以下代码在开发机器上运行:
The following code runs on the development machine:
<?php
$key = "-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0x+2RiQ+LCZNAUcl/Ecf1NrTr
lhjOiHaVC+w/y+UJevqVcDstD22OJGwT13B9T47OuQG9BmzcZQYLcShUMhVD/Owu
9+8PcK51EnBd0lym6+z/WixpnqfQonyKiqq5ytmYKUlUv39J8QQUI2geyvY9VpWS
wyNcFUs7wPl2zsLCPQIDAQAB
-----END PUBLIC KEY-----";
$data = "Hello, world!";
$key1 = openssl_get_publickey($key);
print_r ($key1);
echo "<p>";
$res = openssl_public_encrypt($data, $encrypted_data, $key1, OPENSSL_PKCS1_PADDING);
echo base64_encode($encrypted_data);
在我的开发机器上,此代码输出一个资源和一个编码字符串.我会在这里复制它,但当然它每次都会改变.在生产机器上,此代码产生资源编号和以下 PHP 错误:
On my development machine, this code outputs a resource and an encoded string. I would copy it here, but of course it changes each time. On the production machine, this code produces the resource number and the following PHP errors:
PHP Warning: openssl_public_encrypt(): Don't know how to get public key from this private key in C:xxx est.php on line 15
PHP Warning: openssl_public_encrypt(): key parameter is not a valid public key in C:xxx est.php on line 15
不幸的是,目前无法在生产机器上安装旧版本的 PHP,因为在其上运行的其他应用程序至少需要 5.3.8.
Unfortunately, installing an older version of PHP on the production machine is not an option at the moment because of other applications that are running on it which require 5.3.8 as a minimum.
如果我升级到 5.4.x 会有帮助吗?
Would it help if I upgraded to 5.4.x?
我知道 5.3.5 上的 OpenSSL 版本是 0.9.8,而 5.3.8 中的版本是 1.0.0.我想那里可能有问题.有什么办法可以解决这个问题吗?
I do know that the version of OpenSSL on 5.3.5 is 0.9.8 whereas the version in 5.3.8 is 1.0.0. I imagine that there might be a problem there. Is there any way to work around that?
我试图从 OpenSSL.org 站点和 PHP 错误跟踪器中尽可能多地找出答案,但我不知道我在寻找什么.
I have tried to find out as much as I can from the OpenSSL.org site, and the PHP bug tracker, but I don't know what I'm looking for.
问候,
菲利普
推荐答案
根据这篇文章,该问题与 XAMPP/Windows 安装中的 Apache 和 PHP 的不同 OpenSSL 版本有关.我对 openssl_verify 有类似的问题.我通过对 Apache 和 PHP 使用相同的 OpenSSL 版本(替换 DLL)解决了这个问题.这是解决方案链接.
According to this post, the issue is related to different OpenSSL versions of Apache and PHP in the XAMPP/Windows installation. I had a similar issue with openssl_verify. I solved it by using the same OpenSSL version for both Apache and PHP (replacing DLLs). Here's a link to the solution.
"我找到了问题的解决方案,在默认的 1.7.7 安装中,/apache/bin/中似乎有 2 个错误文件需要替换为/php/中存在的文件 (libeay32.ddl 和 ssleay32.dll)"
这篇关于PHP 上的 OpenSSL 问题 - 不同版本的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!