OpenSSL 目录在 Linux 服务器上正常 - 在 Windows XAMPP 上不行

发布于 2024-09-24 20:02:26 字数 2332 浏览 2 评论 0原文

我有一个 php 脚本,它查找 openssl 目录并加密我拥有的客户数据。

当我将脚本上传到我的在线 linux 目录时 - 加密工作正常

#private key file to use
$MY_KEY_FILE = "my-prvkey.pem";

#public certificate file to use
$MY_CERT_FILE = "my-pubcert.pem";

# Paypal's public certificate
$PAYPAL_CERT_FILE = "paypal_cert_sandbox.pem";

# path to the openssl binary
$OPENSSL = "/usr/bin/openssl";

当我尝试在当前运行 XAMPP 的 Windows 计算机上运行相同的命令时,我无法加密任何内容。还有其他人遇到这个问题吗?

我宁愿在本地更新和测试,也不愿每次在构建过程中进行更改时都必须通过 ftp 传输文件。

编辑

我确实意识到上面的目录主要用于linux;然而,即使我将目录指向 XAMPP 文件夹中的 openssl 目录(对我来说:C:\xampp\apache\bin),操作也会失败。

编辑2

当我说“无法加密”时,我的意思是,即使它们指向正确的目录,也不会返回任何内容(即公钥显然没有找到 openssl .dll 文件)。没有错误消息。配置差异?一种是linux服务器,一种是windows本地机。

在我的脚本中,我包含以下内容:

<?php
function paypal_encrypt($hash) {
    global $MY_KEY_FILE;
    global $MY_CERT_FILE;
    global $PAYPAL_CERT_FILE;
    global $OPENSSL;

    if (!file_exists($MY_KEY_FILE)) {
        echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n"; }
    if (!file_exists($MY_CERT_FILE)) {
        echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n"; }
    if (!file_exists($PAYPAL_CERT_FILE)) {
        echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n"; }
    if (!file_exists($OPENSSL)) {
        echo "ERROR: OPENSSL $OPENSSL not found\n"; }

    $openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " . "-outform der -nodetach -binary | $OPENSSL smime -encrypt " . "-des3 -binary -outform pem $PAYPAL_CERT_FILE";

    $descriptors = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), );
    $process = proc_open($openssl_cmd, $descriptors, $pipes);

    if (is_resource($process)) {
        foreach ($hash as $key => $value) {
            if ($value != "") {
                fwrite($pipes[0], "$key=$value\n");
                }
        }
        fflush($pipes[0]);
        fclose($pipes[0]); 
        $output = ""; 

        while (!feof($pipes[1])) {
            $output .= fgets($pipes[1]); }

            fclose($pipes[1]);
            $return_value = proc_close($process);
            return $output;
    }

    return "ERROR"; }
?> 

在我的 Windows 计算机和 Linux 计算机上显示“错误:未找到 OPENSSL”(即使在 Linux 托管服务器上加密仍然完成)。我可以通过简单地放置 C:\xampp\apache\bin\openssl.exe 来删除 Windows 计算机上的行,但这仍然不进行任何加密)。

I have a php script which looks for the openssl directory and encrypts customer data I have.

When I upload the script to my online linux directory - the encryption works fine

#private key file to use
$MY_KEY_FILE = "my-prvkey.pem";

#public certificate file to use
$MY_CERT_FILE = "my-pubcert.pem";

# Paypal's public certificate
$PAYPAL_CERT_FILE = "paypal_cert_sandbox.pem";

# path to the openssl binary
$OPENSSL = "/usr/bin/openssl";

When I try and run the same command on my Windows machine which runs XAMPP currently, I am unable to encrypt anything. Anybody else had this problem?

I would MUCH rather update and test locally than have to ftp a file every time I make a change during our build.

EDIT

I do realize the directory above is mainly for linux; however even when I point the directory to the openssl directory within the XAMPP folder (for me at: C:\xampp\apache\bin) the operation fails.

EDIT 2

When I say "unable to encrypt" I mean, NOTHING is returned (i.e. the public keys are clearly not finding the openssl .dll files) even though they ARE pointed to the correct directory. There are no error messages. Configuration differences? One is linux server, one is windows local machine.

In my script, I include the following:

<?php
function paypal_encrypt($hash) {
    global $MY_KEY_FILE;
    global $MY_CERT_FILE;
    global $PAYPAL_CERT_FILE;
    global $OPENSSL;

    if (!file_exists($MY_KEY_FILE)) {
        echo "ERROR: MY_KEY_FILE $MY_KEY_FILE not found\n"; }
    if (!file_exists($MY_CERT_FILE)) {
        echo "ERROR: MY_CERT_FILE $MY_CERT_FILE not found\n"; }
    if (!file_exists($PAYPAL_CERT_FILE)) {
        echo "ERROR: PAYPAL_CERT_FILE $PAYPAL_CERT_FILE not found\n"; }
    if (!file_exists($OPENSSL)) {
        echo "ERROR: OPENSSL $OPENSSL not found\n"; }

    $openssl_cmd = "$OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " . "-outform der -nodetach -binary | $OPENSSL smime -encrypt " . "-des3 -binary -outform pem $PAYPAL_CERT_FILE";

    $descriptors = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), );
    $process = proc_open($openssl_cmd, $descriptors, $pipes);

    if (is_resource($process)) {
        foreach ($hash as $key => $value) {
            if ($value != "") {
                fwrite($pipes[0], "$key=$value\n");
                }
        }
        fflush($pipes[0]);
        fclose($pipes[0]); 
        $output = ""; 

        while (!feof($pipes[1])) {
            $output .= fgets($pipes[1]); }

            fclose($pipes[1]);
            $return_value = proc_close($process);
            return $output;
    }

    return "ERROR"; }
?> 

On my windows machine AND the linux machine "Error: OPENSSL not found" is displayed (even though on the linux hosted server the encryption completes anyway). I can remove the line on my windows machine by simply putting C:\xampp\apache\bin\openssl.exe but this still does not do any encrypting).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2024-10-01 20:02:26

将 Windows 路径放入脚本中时,不要忘记转义反斜杠,否则它将被解释为转义字符。您可以在 Windows 版 PHP 中使用正斜杠。

在 Windows 中指定 openssl 路径的两种方法:

$OPENSSL = 'C:\\xampp\\apache\\bin\\openssl.exe';
$OPENSSL = 'C:/xampp/apache/bin/openssl.exe';

PHP 也有 OpenSSL 的扩展: http: //php.net/manual/en/book.openssl.php

When putting a Windows path in your script, do not forget to escape backslashes, otherwise it'll be interpreted as escape characters. You can use forward slashes in PHP for Windows.

Two ways of specifying the openssl path in windows:

$OPENSSL = 'C:\\xampp\\apache\\bin\\openssl.exe';
$OPENSSL = 'C:/xampp/apache/bin/openssl.exe';

PHP does also have an extension for OpenSSL: http://php.net/manual/en/book.openssl.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文