Windows

如何將 PHP 指向腳本中的 OpenSSL 目錄?

  • December 7, 2011

我有一個 PHP 腳本,它需要指向我的伺服器 openssl 目錄,但我迷路了。我知道該目錄位於/usr/bin/openssl,而我的站點頁面位於/var/www/vhosts/domain/httpdocs/test.php。

在 test.php 中,我嘗試使用 /usr/bin/openssl 的相對路徑呼叫 openssl 目錄,但我知道這會導致問題。有人可以幫忙嗎?

試圖呼叫 openssl 進行證書加密的 PHP 腳本:

<?php

//在文件的前面 $ operatingos was set to true or false based on the OS. if(! $ 操作){

#PRIVATE KEY FILE
$MY_KEY_FILE = "my-prvkey.pem";

#PUBLIC KEY FILE
$MY_CERT_FILE = "my-pubcert.pem";

#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
   $PAYPAL_CERT_FILE = "paypal_cert.pem"; //LIVE
} else {
   $PAYPAL_CERT_FILE = "paypal_cert_sandbox.pem"; //SANDBOX
}

#PATH TO OPENSSL BINARY
$OPENSSL = "/usr/bin/openssl";      

} 別的 {

#PRIVATE KEY FILE
$MY_KEY_FILE = "C:\\xampp\\htdocs\\privkey.pem";

#PUBLIC KEY FILE
$MY_CERT_FILE = "C:\\xampp\\htdocs\\pubcert.pempem";

#PAYPAL PUBLIC CERTIFICATE
if(!$testingservices) {
   $PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert.pem";
} else {
   $PAYPAL_CERT_FILE = "C:\\xampp\\htdocs\\pppubcert_sandbox.pem";
}

#PATH TO OPENSSL BINARY
$OPENSSL = "C:\\OpenSSL-Win32\\bin\\openssl.exe"; 

}

$form = array('cmd' => '_xclick',
       'business' => 'email',
       'cert_id' => 'certid',
       'lc' => 'US',
       'custom' => 'test',
       'invoice' => '',
       'currency_code' => 'USD',
       'no_shipping' => '1',
       'item_name' => 'Donation',
       'item_number' => '1',
   'amount' => '10'
   );


   $encrypted = paypal_encrypt($form);


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";
   }


   //Assign Build Notation for PayPal Support
   $hash['bn']= 'domain.PHP_EWP2';

   $data = "";
   foreach ($hash as $key => $value) {
       if ($value != "") {
           //echo "Adding to blob: $key=$value\n";
           $data .= "$key=$value\n";
       }
   }

   $openssl_cmd = "($OPENSSL smime -sign -signer $MY_CERT_FILE -inkey $MY_KEY_FILE " .
                       "-outform der -nodetach -binary <<_EOF_\n$data\n_EOF_\n) | " .
                       "$OPENSSL smime -encrypt -des3 -binary -outform pem $PAYPAL_CERT_FILE";

   exec($openssl_cmd, $output, $error);

   if (!$error) {
       return implode("\n",$output);
   } else {
       return "ERROR: encryption failed";
   }
};
?> 

問題在於 Windows 和 Linux 系統之間的目錄結構不同。我很愚蠢,但需要在 windows 目錄中使用雙斜杠

引用自:https://serverfault.com/questions/160020