PHP上的OpenSSL问题-不同版本的行为不同 [英] Issues with OpenSSL on PHP - different behaviour for different versions
问题描述
(此问题最初发布在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\test.php on line 15
PHP Warning: openssl_public_encrypt(): key parameter is not a valid public key in C:\xxx\test.php on line 15
不幸的是,由于在该机器上运行的其他应用程序至少需要5.3.8,因此暂时无法在生产计算机上安装较旧版本的PHP.
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问题-不同版本的行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!