当前位置: 首页>>代码示例>>PHP>>正文


PHP openssl_pkcs7_encrypt函数代码示例

本文整理汇总了PHP中openssl_pkcs7_encrypt函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_pkcs7_encrypt函数的具体用法?PHP openssl_pkcs7_encrypt怎么用?PHP openssl_pkcs7_encrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了openssl_pkcs7_encrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: encrypt

function encrypt($key, $datFile, $encFile)
{
    if (openssl_pkcs7_encrypt($datFile, $encFile, $key, array())) {
        echo "<b>Successfully encrypted: </b>";
        $tempStr = file_get_contents($encFile);
        $strOri = "MIME-Version: 1.0\nContent-Disposition: attachment; filename=\"smime.p7m\"\nContent-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"\nContent-Transfer-Encoding: base64\n\n";
        $fp = fopen($encFile, "w");
        fwrite($fp, str_replace($strOri, "", $tempStr));
        fclose($fp);
        echo str_replace($strOri, "", $encFile) . "<br/><br/>";
        echo "<b>Encrypted string again, with \"\\n\" replaced with &lt;br&gt and \"\\r\" replaced with [CR]:</b><br>";
        $fp = fopen($encFile, 'r');
        while (false !== ($char = fgetc($fp))) {
            if ($char == "\n") {
                echo "<br>";
            } else {
                if ($char == "\r") {
                    echo "[CR]";
                }
            }
            echo $char;
        }
    } else {
        echo "Cannot Encrypt <br/>";
    }
}
开发者ID:lethanhtung79,项目名称:dooneeweb,代码行数:26,代码来源:SinaptIQPKCS7+(Chananatch+Ruxkukbutra's+conflicted+copy+2013-07-27).php

示例2: encrypt

 private function encrypt($invoice, $msg)
 {
     $key = file_get_contents($this->serverPublicKey);
     //public key for encrypt. This is 123's public key
     $filehash = $invoice . '_' . time();
     $encfile = $this->encryptPath . 'enc_' . $filehash;
     $msgfile = $this->encryptPath . 'msg_' . $filehash;
     try {
         file_put_contents($msgfile, $msg);
         if (openssl_pkcs7_encrypt($msgfile, $encfile, $key, array())) {
             $tempStr = file_get_contents($encfile);
             $strOri = "MIME-Version: 1.0\nContent-Disposition: attachment; filename=\"smime.p7m\"\nContent-Type: application/x-pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"\nContent-Transfer-Encoding: base64\n\n";
             $pos = strpos($tempStr, "base64");
             $tempStr = trim(substr($tempStr, $pos + 6));
             unlink($encfile);
             unlink($msgfile);
             return str_replace($strOri, "", $tempStr);
         } else {
             echo "Error";
             error_log("Encrypt error on One23Payment Library =>" . $msgfile);
             unlink($encfile);
             return false;
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
开发者ID:lethanhtung79,项目名称:dooneeweb,代码行数:27,代码来源:One23Payment.php

示例3: signAndEncrypt

 /**
  * Sign and Envelope the passed data string, returning a PKCS7 blob that can be posted to PayPal.
  * Make sure the passed data string is seperated by UNIX linefeeds (ASCII 10, '\n').
  *
  * @param	string	The candidate for signature and encryption
  * @param	string	The file path to the EWP(merchant) certificate
  * @param	string	The file path to the EWP(merchant) private key
  * @param	string	The EWP(merchant) private key password
  * @param	string	The file path to the PayPal Certificate
  * @return	array	Contains a bool status, error_msg, error_no, and an encrypted string: encryptedData if successfull
  *
  * @access	public
  * @static
  */
 function signAndEncrypt($dataStr_, $ewpCertPath_, $ewpPrivateKeyPath_, $ewpPrivateKeyPwd_, $paypalCertPath_)
 {
     $dataStrFile = realpath(tempnam('/tmp', 'pp_'));
     $fd = fopen($dataStrFile, 'w');
     if (!$fd) {
         $error = "Could not open temporary file {$dataStrFile}.";
         return array("status" => false, "error_msg" => $error, "error_no" => 0);
     }
     fwrite($fd, $dataStr_);
     fclose($fd);
     $signedDataFile = realpath(tempnam('/tmp', 'pp_'));
     if (!@openssl_pkcs7_sign($dataStrFile, $signedDataFile, "file://{$ewpCertPath_}", array("file://{$ewpPrivateKeyPath_}", $ewpPrivateKeyPwd_), array(), PKCS7_BINARY)) {
         unlink($dataStrFile);
         unlink($signedDataFile);
         $error = "Could not sign data: " . openssl_error_string();
         return array("status" => false, "error_msg" => $error, "error_no" => 0);
     }
     unlink($dataStrFile);
     $signedData = file_get_contents($signedDataFile);
     $signedDataArray = explode("\n\n", $signedData);
     $signedData = $signedDataArray[1];
     $signedData = base64_decode($signedData);
     unlink($signedDataFile);
     $decodedSignedDataFile = realpath(tempnam('/tmp', 'pp_'));
     $fd = fopen($decodedSignedDataFile, 'w');
     if (!$fd) {
         $error = "Could not open temporary file {$decodedSignedDataFile}.";
         return array("status" => false, "error_msg" => $error, "error_no" => 0);
     }
     fwrite($fd, $signedData);
     fclose($fd);
     $encryptedDataFile = realpath(tempnam('/tmp', 'pp_'));
     if (!@openssl_pkcs7_encrypt($decodedSignedDataFile, $encryptedDataFile, file_get_contents($paypalCertPath_), array(), PKCS7_BINARY)) {
         unlink($decodedSignedDataFile);
         unlink($encryptedDataFile);
         $error = "Could not encrypt data: " . openssl_error_string();
         return array("status" => false, "error_msg" => $error, "error_no" => 0);
     }
     unlink($decodedSignedDataFile);
     $encryptedData = file_get_contents($encryptedDataFile);
     if (!$encryptedData) {
         $error = "Encryption and signature of data failed.";
         return array("status" => false, "error_msg" => $error, "error_no" => 0);
     }
     unlink($encryptedDataFile);
     $encryptedDataArray = explode("\n\n", $encryptedData);
     $encryptedData = trim(str_replace("\n", '', $encryptedDataArray[1]));
     return array("status" => true, "encryptedData" => $encryptedData);
 }
开发者ID:pjmoore92,项目名称:teamo-webtranslator,代码行数:63,代码来源:PPCrypto.php

示例4: encrypt

function encrypt($key, $msg)
{
    $msgfile = "msg.txt";
    $encfile = "enc.txt";
    $decfile = "dec.txt";
    file_put_contents($msgfile, $msg);
    if (openssl_pkcs7_encrypt($msgfile, $encfile, $key, array())) {
        echo "<b>Successfully encrypted: </b>";
        $tempStr = file_get_contents($encfile);
        $pos = strpos($tempStr, "base64");
        $tempStr = trim(substr($tempStr, $pos + 6));
        return str_replace($strOri, "", $tempStr);
    } else {
        echo "Cannot Encrypt <br/>";
        return "Cannot Encrypt";
    }
}
开发者ID:lethanhtung79,项目名称:dooneeweb,代码行数:17,代码来源:SinaptIQPKCS7.php

示例5: encryptData

 public function encryptData($data)
 {
     if ($this->certificateID == '' || !isset($this->certificate) || !isset($this->paypalCertificate)) {
         return FALSE;
     }
     sfContext::getInstance()->getLogger()->warning('esPaypalButton: data ...');
     $parameters = array();
     $data['cert_id'] = $this->certificateID;
     foreach ($data as $key => $value) {
         $parameters[] = "{$key}={$value}";
         sfContext::getInstance()->getLogger()->warning("{$key}={$value}");
     }
     $clearText = join("\n", $parameters);
     sfContext::getInstance()->getLogger()->warning($clearText);
     $clearFile = tempnam('/tmp', 'clear');
     $signedFile = tempnam('/tmp', 'signed');
     $encryptedFile = tempnam('/tmp', 'encrypted');
     $out = fopen($clearFile, 'wb');
     fwrite($out, $clearText);
     fclose($out);
     if (!openssl_pkcs7_sign($clearFile, $signedFile, $this->certificate, $this->privateKey, array(), PKCS7_BINARY)) {
         return FALSE;
     }
     $signedData = explode("\n\n", file_get_contents($signedFile));
     $out = fopen($signedFile, 'wb');
     fwrite($out, base64_decode($signedData[1]));
     fclose($out);
     if (!openssl_pkcs7_encrypt($signedFile, $encryptedFile, $this->paypalCertificate, array(), PKCS7_BINARY)) {
         return FALSE;
     }
     $encryptedData = explode("\n\n", file_get_contents($encryptedFile));
     $encryptedText = $encryptedData[1];
     @unlink($clearFile);
     @unlink($signedFile);
     @unlink($encryptedFile);
     return sprintf('-----BEGIN PKCS7-----%s-----END PKCS7-----', trim(str_replace("\n", "", $encryptedText)));
 }
开发者ID:jmiridis,项目名称:atcsf1,代码行数:37,代码来源:esPaypalEncryptor.class.php

示例6: encrypt

 /**
  * Use our encryption certificate to encrypt the given parameters.
  *
  * @param  array $params
  * @return string
  */
 public function encrypt(array $params)
 {
     // Make sure we have the data we need
     if (empty($this->certificate_id) || empty($this->public_cert) || empty($this->paypal_cert)) {
         throw new SecurityException('Please set your public certificate, PayPal certificate and certificate ID');
     }
     // Compose clear text data
     $encrypted_text = '';
     $clear_text = 'cert_id=' . $this->certificate_id;
     foreach ($params as $key => $param) {
         $clear_text .= sprintf("\n%s=%s", $key, $param);
     }
     // Generate temporary file names for various certs
     $clear_file = tempnam($this->tmp_dir, 'clear_');
     $signed_file = str_replace('clear', 'signed', $clear_file);
     $encrypted_file = str_replace('clear', 'encrypted', $clear_file);
     // Write our clear text file
     $out = fopen($clear_file, 'wb');
     fwrite($out, $clear_text);
     fclose($out);
     // Sign our clear text file
     if (!openssl_pkcs7_sign($clear_file, $signed_file, $this->public_cert, $this->private_key, [], PKCS7_BINARY)) {
         throw new SecurityException('Unable to sign file');
     }
     // Get back our signed file contents
     $signed_data = explode("\n\n", file_get_contents($signed_file));
     // Write the signed file contents (part of them)
     $out = fopen($signed_file, 'wb');
     fwrite($out, base64_decode($signed_data[1]));
     fclose($out);
     // Encrypt our signed file
     if (!openssl_pkcs7_encrypt($signed_file, $encrypted_file, $this->paypal_cert, [], PKCS7_BINARY)) {
         throw new SecurityException('Unable to encrypt file');
     }
     // Get the encrypted data
     $encrypted_data = explode("\n\n", file_get_contents($encrypted_file));
     $encrypted_text = $encrypted_data[1];
     // Delete temporary files
     @unlink($clear_file);
     @unlink($signed_file);
     @unlink($encrypted_file);
     // Signature
     $encrypted_text = "-----BEGIN PKCS7-----\n" . $encrypted_text . "\n-----END PKCS7-----";
     return $encrypted_text;
 }
开发者ID:ausbin,项目名称:paypal-tools,代码行数:51,代码来源:EncryptedButton.php

示例7: _encryptMessage

 /**
  * Encrypt a message in S/MIME format using a public key.
  *
  * @param string $text   The text to be encrypted.
  * @param array $params  The parameters needed for encryption.
  * <pre>
  * Parameters:
  * ===========
  * 'type'   => 'message' (REQUIRED)
  * 'pubkey' => public key (REQUIRED)
  * </pre>
  *
  * @return string  The encrypted message.
  * @throws Horde_Crypt_Exception
  */
 protected function _encryptMessage($text, $params)
 {
     /* Check for required parameters. */
     if (!isset($params['pubkey'])) {
         throw new Horde_Crypt_Exception(Horde_Crypt_Translation::t("A public S/MIME key is required to encrypt a message."));
     }
     /* Create temp files for input/output. */
     $input = $this->_createTempFile('horde-smime');
     $output = $this->_createTempFile('horde-smime');
     /* Store message in file. */
     file_put_contents($input, $text);
     unset($text);
     /* Encrypt the document. */
     $ciphers = array(OPENSSL_CIPHER_3DES, OPENSSL_CIPHER_DES, OPENSSL_CIPHER_RC2_128, OPENSSL_CIPHER_RC2_64, OPENSSL_CIPHER_RC2_40);
     foreach ($ciphers as $val) {
         if (openssl_pkcs7_encrypt($input, $output, $params['pubkey'], array(), 0, $val)) {
             $result = file_get_contents($output);
             if (!empty($result)) {
                 return $this->_fixContentType($result, 'encrypt');
             }
         }
     }
     throw new Horde_Crypt_Exception(Horde_Crypt_Translation::t("Could not S/MIME encrypt message."));
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:39,代码来源:Smime.php

示例8: encryptx509

 public function encryptx509($fin, $fout, $k, $o)
 {
     openssl_pkcs7_encrypt($fin, $fout, $k, $o);
     return $fout;
 }
开发者ID:jas-,项目名称:jQuery.pidCrypt,代码行数:5,代码来源:class.openssl.php

示例9: encryptButton

 function encryptButton($parameters)
 {
     // Check encryption data is available.
     if ($this->certificateID == '' || !isset($this->certificate) || !isset($this->paypalCertificate)) {
         return false;
     }
     $clearText = '';
     $encryptedText = '';
     if ($this->os == 'windows') {
         // initialize data.
         $data = "cert_id=" . $this->certificateID . "\n";
         foreach ($parameters as $k => $v) {
             $d[] = "{$k}={$v}";
         }
         $data .= join("\n", $d);
         $dataFile = tempnam($this->tempFileDirectory, 'data');
         $out = fopen("{$dataFile}_data.txt", 'wb');
         fwrite($out, $data);
         fclose($out);
         $out = fopen("{$dataFile}_signed.txt", "w+");
         if (!openssl_pkcs7_sign("{$dataFile}_data.txt", "{$dataFile}_signed.txt", $this->certificate, $this->privateKey, array(), PKCS7_BINARY)) {
             return false;
         }
         fclose($out);
         $signedData = explode("\n\n", file_get_contents("{$dataFile}_signed.txt"));
         $out = fopen("{$dataFile}_signed.txt", 'wb');
         fwrite($out, base64_decode($signedData[1]));
         fclose($out);
         if (!openssl_pkcs7_encrypt("{$dataFile}_signed.txt", "{$dataFile}_encrypted.txt", $this->paypalCertificate, array(), PKCS7_BINARY)) {
             return false;
         }
         $encryptedData = explode("\n\n", file_get_contents("{$dataFile}_encrypted.txt"));
         $encryptedText = $encryptedData[1];
         @unlink($dataFile);
         @unlink("{$dataFile}_data.txt");
         @unlink("{$dataFile}_signed.txt");
         @unlink("{$dataFile}_encrypted.txt");
     } else {
         // Compose clear text data.
         $clearText = 'cert_id=' . $this->certificateID;
         foreach (array_keys($parameters) as $key) {
             $clearText .= "\n{$key}={$parameters[$key]}";
         }
         $clearFile = tempnam($this->tempFileDirectory, 'clear_');
         $signedFile = preg_replace('/clear/', 'signed', $clearFile);
         $encryptedFile = preg_replace('/clear/', 'encrypted', $clearFile);
         $out = fopen($clearFile, 'wb');
         fwrite($out, $clearText);
         fclose($out);
         if (!openssl_pkcs7_sign($clearFile, $signedFile, $this->certificate, $this->privateKey, array(), PKCS7_BINARY)) {
             return FALSE;
         }
         $signedData = explode("\n\n", file_get_contents($signedFile));
         $out = fopen($signedFile, 'wb');
         fwrite($out, base64_decode($signedData[1]));
         fclose($out);
         if (!openssl_pkcs7_encrypt($signedFile, $encryptedFile, $this->paypalCertificate, array(), PKCS7_BINARY)) {
             return FALSE;
         }
         $encryptedData = explode("\n\n", file_get_contents($encryptedFile));
         $encryptedText = $encryptedData[1];
         @unlink($clearFile);
         @unlink($signedFile);
         @unlink($encryptedFile);
         //return $clearText;
     }
     return $encryptedText;
 }
开发者ID:kevthunder,项目名称:cake-shop,代码行数:68,代码来源:paypal_old.php

示例10: encrypt_data

 /** ----------------------------------------
 	/**  Encrypt Button
 	/** ----------------------------------------*/
 function encrypt_data($params = array(), $type = 'button')
 {
     /** -----------------------------
     		/**  Certificates, Keys, and TMP Files
     		/** -----------------------------*/
     $public_certificate = file_get_contents($this->public_certificate);
     $private_key = file_get_contents($this->private_key);
     $paypal_certificate = file_get_contents($this->paypal_certificate);
     $tmpin_file = tempnam($this->temp_path, 'paypal_');
     $tmpout_file = tempnam($this->temp_path, 'paypal_');
     $tmpfinal_file = tempnam($this->temp_path, 'paypal_');
     /** -----------------------------
     		/**  Prepare Our Data
     		/** -----------------------------*/
     $rawdata = '';
     $params['cert_id'] = $this->certificate_id;
     foreach ($params as $name => $value) {
         $rawdata .= "{$name}={$value}\n";
     }
     if (!($fp = fopen($tmpin_file, 'w'))) {
         exit('failure');
     }
     fwrite($fp, rtrim($rawdata));
     fclose($fp);
     /** -----------------------------
     		/**  Sign Our File
     		/** -----------------------------*/
     if (!openssl_pkcs7_sign($tmpin_file, $tmpout_file, $public_certificate, $private_key, array(), PKCS7_BINARY)) {
         exit("Could not sign encrypted data: " . openssl_error_string());
     }
     $data = explode("\n\n", file_get_contents($tmpout_file));
     $data = base64_decode($data['1']);
     if (!($fp = fopen($tmpout_file, 'w'))) {
         exit("Could not open temporary file '{$tmpin_file}')");
     }
     fwrite($fp, $data);
     fclose($fp);
     /** -----------------------------
     		/**  Encrypt Our Data
     		/** -----------------------------*/
     if (!openssl_pkcs7_encrypt($tmpout_file, $tmpfinal_file, $paypal_certificate, array(), PKCS7_BINARY)) {
         exit("Could not encrypt data:" . openssl_error_string());
     }
     $encdata = file_get_contents($tmpfinal_file, FALSE);
     if (empty($encdata)) {
         exit("Encryption and signature of data failed.");
     }
     $encdata = explode("\n\n", $encdata);
     $encdata = trim(str_replace("\n", '', $encdata['1']));
     $encdata = "-----BEGIN PKCS7-----" . $encdata . "-----END PKCS7-----";
     @unlink($tmpfinal_file);
     @unlink($tmpin_file);
     @unlink($tmpout_file);
     /** -----------------------------
     		/**  Return The Encrypted Data String
     		/** -----------------------------*/
     return $encdata;
 }
开发者ID:nigelpeters,项目名称:css-recruitment-ee,代码行数:61,代码来源:mod.simple_commerce.php

示例11: die

if ($outfile2 === false) {
    die("failed to get a temporary filename!");
}
$single_cert = "file://" . dirname(__FILE__) . "/cert.crt";
$privkey = "file://" . dirname(__FILE__) . "/private.key";
$multi_certs = array($single_cert, $single_cert);
$assoc_headers = array("To" => "test@test", "Subject" => "testing openssl_pkcs7_encrypt()");
$headers = array("test@test", "testing openssl_pkcs7_encrypt()");
$empty_headers = array();
$wrong = "wrong";
$empty = "";
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $headers));
var_dump(openssl_pkcs7_decrypt($outfile, $outfile2, $single_cert, $privkey));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $assoc_headers));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $empty_headers));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $wrong));
var_dump(openssl_pkcs7_encrypt($wrong, $outfile, $single_cert, $headers));
var_dump(openssl_pkcs7_encrypt($empty, $outfile, $single_cert, $headers));
var_dump(openssl_pkcs7_encrypt($infile, $empty, $single_cert, $headers));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $wrong, $headers));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $empty, $headers));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $single_cert, $empty));
var_dump(openssl_pkcs7_encrypt($infile, $outfile, $multi_certs, $headers));
if (file_exists($outfile)) {
    echo "true\n";
    unlink($outfile);
}
if (file_exists($outfile2)) {
    echo "true\n";
    unlink($outfile2);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:023.php

示例12: process_button

 function process_button()
 {
     global $customer_id, $order, $languages_id, $currencies, $currency, $cart_PayPal_IPN_ID, $shipping;
     if (MODULE_PAYMENT_PAYPAL_IPN_CURRENCY == 'Selected Currency') {
         $my_currency = $currency;
     } else {
         $my_currency = substr(MODULE_PAYMENT_PAYPAL_IPN_CURRENCY, 5);
     }
     if (!in_array($my_currency, array('CAD', 'EUR', 'GBP', 'JPY', 'USD'))) {
         $my_currency = 'USD';
     }
     $parameters = array();
     if (MODULE_PAYMENT_PAYPAL_IPN_TRANSACTION_TYPE == 'Per Item' && MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'False') {
         $parameters['cmd'] = '_cart';
         $parameters['upload'] = '1';
         for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {
             $item = $i + 1;
             $tax_value = $order->products[$i]['tax'] / 100 * $order->products[$i]['final_price'];
             $parameters['item_name_' . $item] = $order->products[$i]['name'];
             $parameters['amount_' . $item] = number_format($order->products[$i]['final_price'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
             $parameters['tax_' . $item] = number_format($tax_value * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
             $parameters['quantity_' . $item] = $order->products[$i]['qty'];
             if ($i == 0) {
                 if (DISPLAY_PRICE_WITH_TAX == 'true') {
                     $shipping_cost = $order->info['shipping_cost'];
                 } else {
                     $module = substr($shipping['id'], 0, strpos($shipping['id'], '_'));
                     $shipping_tax = tep_get_tax_rate($GLOBALS[$module]->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
                     $shipping_cost = $order->info['shipping_cost'] + tep_calculate_tax($order->info['shipping_cost'], $shipping_tax);
                 }
                 $parameters['shipping_' . $item] = number_format($shipping_cost * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
             }
             if (isset($order->products[$i]['attributes'])) {
                 for ($j = 0, $n2 = sizeof($order->products[$i]['attributes']); $j < $n2; $j++) {
                     if (DOWNLOAD_ENABLED == 'true') {
                         $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename\r\n                                     from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa\r\n                                     left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad\r\n                                     on pa.products_attributes_id=pad.products_attributes_id\r\n                                     where pa.products_id = '" . $order->products[$i]['id'] . "'\r\n                                     and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'\r\n                                     and pa.options_id = popt.products_options_id\r\n                                     and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'\r\n                                     and pa.options_values_id = poval.products_options_values_id\r\n                                     and popt.language_id = '" . $languages_id . "'\r\n                                     and poval.language_id = '" . $languages_id . "'";
                         $attributes = tep_db_query($attributes_query);
                     } else {
                         $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
                     }
                     $attributes_values = tep_db_fetch_array($attributes);
                     // Unfortunately PayPal only accepts two attributes per product, so the
                     // third attribute onwards will not be shown at PayPal
                     $parameters['on' . $j . '_' . $item] = $attributes_values['products_options_name'];
                     $parameters['os' . $j . '_' . $item] = $attributes_values['products_options_values_name'];
                 }
             }
         }
         $parameters['num_cart_items'] = $item;
     } else {
         $parameters['cmd'] = '_xclick';
         $parameters['item_name'] = STORE_NAME;
         $parameters['shipping'] = number_format($order->info['shipping_cost'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
         $parameters['tax'] = number_format($order->info['tax'] * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     }
     $parameters['business'] = MODULE_PAYMENT_PAYPAL_IPN_ID;
     $parameters['amount'] = number_format(($order->info['total'] - $order->info['shipping_cost'] - $order->info['tax']) * $currencies->get_value($my_currency), $currencies->get_decimal_places($my_currency));
     $parameters['currency_code'] = $my_currency;
     $parameters['invoice'] = substr($cart_PayPal_IPN_ID, strpos($cart_PayPal_IPN_ID, '-') + 1);
     $parameters['custom'] = $customer_id;
     $parameters['no_shipping'] = '1';
     $parameters['no_note'] = '1';
     $parameters['notify_url'] = tep_href_link('ext/modules/payment/paypal_ipn/ipn.php', '', 'SSL', false, false);
     $parameters['return'] = tep_href_link(FILENAME_CHECKOUT_PROCESS, '', 'SSL');
     $parameters['cancel_return'] = tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL');
     $parameters['bn'] = $this->identifier;
     if (tep_not_null(MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE)) {
         $parameters['page_style'] = MODULE_PAYMENT_PAYPAL_IPN_PAGE_STYLE;
     }
     if (MODULE_PAYMENT_PAYPAL_IPN_EWP_STATUS == 'True') {
         $parameters['cert_id'] = MODULE_PAYMENT_PAYPAL_IPN_EWP_CERT_ID;
         $random_string = rand(100000, 999999) . '-' . $customer_id . '-';
         $data = '';
         while (list($key, $value) = each($parameters)) {
             $data .= $key . '=' . $value . "\n";
         }
         $fp = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', 'w');
         fwrite($fp, $data);
         fclose($fp);
         unset($data);
         if (function_exists('openssl_pkcs7_sign') && function_exists('openssl_pkcs7_encrypt')) {
             openssl_pkcs7_sign(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt', MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PUBLIC_KEY), file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PRIVATE_KEY), array('From' => MODULE_PAYMENT_PAYPAL_IPN_ID), PKCS7_BINARY);
             unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt');
             // remove headers from the signature
             $signed = file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             $signed = explode("\n\n", $signed);
             $signed = base64_decode($signed[1]);
             $fp = fopen(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', 'w');
             fwrite($fp, $signed);
             fclose($fp);
             unset($signed);
             openssl_pkcs7_encrypt(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt', MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt', file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_PAYPAL_KEY), array('From' => MODULE_PAYMENT_PAYPAL_IPN_ID), PKCS7_BINARY);
             unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
             // remove headers from the encrypted result
             $data = file_get_contents(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
             $data = explode("\n\n", $data);
             $data = '-----BEGIN PKCS7-----' . "\n" . $data[1] . "\n" . '-----END PKCS7-----';
             unlink(MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'encrypted.txt');
         } else {
             exec(MODULE_PAYMENT_PAYPAL_IPN_EWP_OPENSSL . ' smime -sign -in ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'data.txt -signer ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_PUBLIC_KEY . ' -inkey ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_PRIVATE_KEY . ' -outform der -nodetach -binary > ' . MODULE_PAYMENT_PAYPAL_IPN_EWP_WORKING_DIRECTORY . '/' . $random_string . 'signed.txt');
//.........这里部分代码省略.........
开发者ID:eosc,项目名称:EosC-2.3,代码行数:101,代码来源:paypal_ipn.php

示例13: generatePublicEncryptionKey

 /**
  * Compute public encryption key
  */
 protected function generatePublicEncryptionKey()
 {
     $keybytelen = $this->encryptdata['Length'] / 8;
     // random 20-byte seed
     $seed = sha1($this->encrypt('seed'), true);
     $recipient_bytes = '';
     foreach ($this->encryptdata['pubkeys'] as $pubkey) {
         // for each public certificate
         if (isset($pubkey['p'])) {
             $pkprotection = $this->getUserPermissionCode($pubkey['p'], $this->encryptdata['mode']);
         } else {
             $pkprotection = $this->encryptdata['protection'];
         }
         // get default permissions (reverse byte order)
         $pkpermissions = $this->getEncPermissionsString($pkprotection);
         // envelope data
         $envelope = $seed . $pkpermissions;
         // write the envelope data to a temporary file
         $tempkeyfile = tempnam(sys_get_temp_dir(), '__tcpdf_key_' . md5($this->encryptdata['fileid'] . $envelope) . '_');
         if (file_put_contents($tempkeyfile, $envelope) === false) {
             // @codeCoverageIgnoreStart
             throw new EncException('Unable to create temporary key file: ' . $tempkeyfile);
             // @codeCoverageIgnoreEnd
         }
         $tempencfile = tempnam(sys_get_temp_dir(), '__tcpdf_enc_' . md5($this->encryptdata['fileid'] . $envelope) . '_');
         if (!function_exists('openssl_pkcs7_encrypt') || !openssl_pkcs7_encrypt($tempkeyfile, $tempencfile, file_get_contents($pubkey['c']), array(), PKCS7_BINARY | PKCS7_DETACHED)) {
             throw new EncException('Unable to encrypt the file: ' . $tempkeyfile . "\n" . 'Public-Key Security requires openssl_pkcs7_encrypt.');
         }
         // read encryption signature
         $signature = file_get_contents($tempencfile);
         // extract signature
         $signature = substr($signature, strpos($signature, 'Content-Disposition'));
         $tmparr = explode("\n\n", $signature);
         $signature = trim($tmparr[1]);
         unset($tmparr);
         // decode signature
         $signature = base64_decode($signature);
         // convert signature to hex
         $hexsignature = current(unpack('H*', $signature));
         // store signature on recipients array
         $this->encryptdata['Recipients'][] = $hexsignature;
         // The bytes of each item in the Recipients array of PKCS#7 objects
         // in the order in which they appear in the array
         $recipient_bytes .= $signature;
     }
     // calculate encryption key
     if ($this->encryptdata['mode'] == 3) {
         // AES-256
         $this->encryptdata['key'] = substr(hash('sha256', $seed . $recipient_bytes, true), 0, $keybytelen);
     } else {
         // RC4-40, RC4-128, AES-128
         $this->encryptdata['key'] = substr(sha1($seed . $recipient_bytes, true), 0, $keybytelen);
     }
 }
开发者ID:tecnickcom,项目名称:tc-lib-pdf-encrypt,代码行数:57,代码来源:Compute.php

示例14: _paypalEncrypt

	/**
	 * Encrypts and signs the request to paypal
	 *
	 * To generate a keypair:
	 * openssl genrsa -des3 -out privkey.pem 2048
	 * openssl req -new -x509 -key privkey.pem -out cacert.pem -days 3650
	 * 
	 * To encrypt and sign (that's what we do here):
	 * openssl smime -sign -signer cacert.pem -inkey privkey.pem -outform der -nodetach -binary -passin pass:1234 | openssl smime -encrypt -des3 -binary -outform pem paypal_cert_pem.txt
	 *
	 * @param  string        $cleartext  Cleartext to encrypt and sign
	 * @return string                    Encrypted text or FALSE
	 */
	private function _paypalEncrypt( $cleartext )
	{
		$return							=	false;

		$paypal_openssl_path			=	$this->params->get( 'openssl_exec_path', '/usr/bin/openssl' );
		$paypal_public_certificate_path	=	$this->getAccountParam( 'paypal_public_certificate_path' );
		$paypal_private_key_path		=	$this->getAccountParam( 'paypal_private_key_path' );
		$paypal_public_key_path			=	$this->getAccountParam( 'paypal_public_key_path' );
		$paypal_private_key_password	=	$this->getAccountParam( 'paypal_private_key_password' );

		$tmpDir							=	$this->findATmpDir();
		if ( ( $tmpDir === null ) || ( ! is_dir( $tmpDir ) ) || ! is_writable( $tmpDir ) ) {
			$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl', 'did not find a writable temporary directory (' . $tmpDir . '). Please make sure that your cachepath global CMS setting is a writable directory.' );
			$tmpDir						=	null;
		}

		$h = @getenv('HOME') . "\n";
		if ( ! is_writable( $h ) ) {
			@putenv("HOME=/tmp");		// try avoiding unable to write 'random state'		( http://www.paypaldeveloper.com/pdn/board/message?board.id=ewp&thread.id=110&view=by_date_ascending&page=2 )
		} else {
			$h			=	null;
		}

		if ( extension_loaded( 'openssl' ) && defined( 'OPENSSL_VERSION_TEXT' ) && ( $tmpDir !== null ) ) {

			$clearFile					=	tempnam($tmpDir, 'clr_');
			$signedFile					=	tempnam($tmpDir, 'sign_');
			$encryptedFile				=	tempnam($tmpDir, 'encr_');

			if ( is_readable( $paypal_public_key_path ) && is_readable( $paypal_private_key_path ) && is_readable( $paypal_public_certificate_path ) ) {
				$certificate			=	openssl_x509_read( file_get_contents( $paypal_public_key_path ) );
				$privateKey				=	openssl_pkey_get_private( file_get_contents( $paypal_private_key_path ), $paypal_private_key_password );
				$paypalcert				=	openssl_x509_read( file_get_contents( $paypal_public_certificate_path ) );
				if ( ( $certificate !== false ) && ( $privateKey !== false ) && ( $paypalcert !== false ) ) {
					$privOk				=	openssl_x509_check_private_key( $certificate, $privateKey );
					if ( $privOk ) {
						$out			=	fopen( $clearFile, 'wb' );
						if ( $out !== false ) {
							fwrite( $out, $cleartext );
							fclose( $out );
	
							if ( openssl_pkcs7_sign( $clearFile, $signedFile, $certificate, $privateKey, array(), PKCS7_BINARY ) ) {
								@unlink( $clearFile );
			
								$signedData		=	explode( "\n\n", file_get_contents( $signedFile ) );
				
								$out			=	fopen($signedFile, 'wb');
								if ( $out !== false ) {
									fwrite( $out, base64_decode( $signedData[1] ) );
									fclose( $out );
				
									if ( openssl_pkcs7_encrypt( $signedFile, $encryptedFile, $paypalcert, array(), PKCS7_BINARY ) ) {
										@unlink( $signedFile );
										$encryptedData	=	explode("\n\n", file_get_contents( $encryptedFile ), 2 );
										@unlink( $encryptedFile );

										$return	=	"-----BEGIN PKCS7-----\n"
												.	trim( $encryptedData[1] )
												.	"\n-----END PKCS7-----";
									} else {
										$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_pkcs7_encrypt(signedFile,paypal_public_cer) ', 'returns an error on signature.' );
									}
								} else {
									$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl open ', $signedFile . ' returns an error creating it.' );
								}
							} else {
								$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_pkcs7_sign(message,your_private_key)', 'returns an error.' );
							}
						} else {
							$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl open ', $clearFile . ' returns an error creating it.' );
						}	
					} else {
						$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_pkcs7_sign(message,your_private_key)', 'returns an error.' );
					}
				} else {
					if ( $certificate === false ) {
						$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_x509_read(your_public_key)', 'returns an error.' );
					}
					if ( $privateKey === false ) {
						$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_pkey_get_private(your_private_key)', 'returns an error. Maybe wrong password for private key ?' );
					}
					if ( $paypalcert === false ) {
						$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl_x509_read(paypal_public_certificate)', 'returns an error.' );
					}
				}
			} else {
				$this->_setLogErrorMSG( 3, $this->account, 'paypal openssl tempnam()', 'returns unwritable filepaths (' . $clearFile . ')' );
//.........这里部分代码省略.........
开发者ID:kosmosby,项目名称:medicine-prof,代码行数:101,代码来源:cbpaidsubscriptions.paypal.php

示例15: encrypt

 function encrypt($certificate_id)
 {
     # since this is a shared class, but certs are site-specific, go through include_paths to find realpath
     foreach (explode(':', ini_get('include_path')) as $path) {
         if (file_exists($path . '/paypal/paypal.cert')) {
             $public_file = realpath($path . '/paypal/public.cert');
             $private_file = realpath($path . '/paypal/private.cert');
             $paypal_file = realpath($path . '/paypal/paypal.cert');
             $public_cert = openssl_x509_read(file_get_contents($public_file));
             $private_cert = openssl_get_privatekey(file_get_contents($private_file));
             if (openssl_x509_check_private_key($public_cert, $private_cert) === false) {
                 return false;
             }
             $paypal_cert = openssl_x509_read(file_get_contents($paypal_file));
             break;
         }
     }
     $clear_text = 'cert_id=' . $certificate_id;
     foreach ($this->postvars() as $k => $v) {
         $clear_text .= "\n" . $k . '=' . $v;
     }
     $clear_file = tempnam('/tmp/', 'clear_');
     # alt: sys_get_temp_dir()
     $signed_file = preg_replace('/clear/', 'signed', $clear_file);
     $encrypted_file = preg_replace('/clear/', 'encrypted', $clear_file);
     file_put_contents($clear_file, $clear_text);
     if (!openssl_pkcs7_sign($clear_file, $signed_file, $public_cert, $private_cert, array(), PKCS7_BINARY)) {
         return false;
     }
     list($x, $signed_text) = explode("\n\n", file_get_contents($signed_file));
     #?
     file_put_contents($signed_file, base64_decode($signed_text));
     if (!openssl_pkcs7_encrypt($signed_file, $encrypted_file, $paypal_cert, array(), PKCS7_BINARY)) {
         return false;
     }
     list($x, $encrypted_text) = explode("\n\n", file_get_contents($encrypted_file));
     #?
     $this->encrypted = "\n-----BEGIN PKCS7-----\n{$encrypted_text}\n-----END PKCS7-----\n";
     @unlink($clear_file);
     @unlink($signed_file);
     @unlink($encrypted_file);
 }
开发者ID:songwork,项目名称:songwork,代码行数:42,代码来源:PayPalButton.php


注:本文中的openssl_pkcs7_encrypt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。