PHP 上的 OpenSSL 问题 - 不同版本的不同行为

2023-10-15php开发问题
71

本文介绍了PHP 上的 OpenSSL 问题 - 不同版本的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

(这个问题最初发布在 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 问题 - 不同版本的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17