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


PHP openssl_pkcs7_sign函数代码示例

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


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

示例1: sign_pkcs7

 private function sign_pkcs7($xml)
 {
     $dataFile = $this->rwTmpFile($xml);
     $signedFile = $this->rwTmpFile();
     if (openssl_pkcs7_sign($dataFile, $signedFile, $this->CertPem, $this->PkeyPem, array(), PKCS7_NOCHAIN + PKCS7_NOCERTS)) {
         $signedData = explode("\n\n", file_get_contents($signedFile));
         return "-----BEGIN PKCS7-----\n" . $signedData[1] . "\n-----END PKCS7-----";
     }
 }
开发者ID:andre2git,项目名称:yandex-money-cms-opencart2,代码行数:9,代码来源:mws.php

示例2: 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

示例3: signature

 public function signature($manifest_path, $signature_path)
 {
     $private_key = openssl_pkey_get_private($this->certs['pkey'], $this->cert_password);
     if (file_exists(\Fuel\Core\Config::get('pass.WWDR_cert'))) {
         try {
             openssl_pkcs7_sign($manifest_path, $signature_path, $this->cert_data, $private_key, array(), PKCS7_BINARY | PKCS7_DETACHED, \Fuel\Core\Config::get('pass.WWDR_cert'));
         } catch (Exception $e) {
             $this->error = 'Certificate error.';
             return null;
         }
     } else {
         $this->error = 'WWDR Intermediate Certificate does not exist.';
         return false;
     }
     $signature = file_get_contents($signature_path);
     $signature = $this->convert_PEM2DER($signature);
     return $signature;
 }
开发者ID:rizumita,项目名称:PassCurrent,代码行数:18,代码来源:certificate.php

示例4: SignTRA

function SignTRA()
{
    $STATUS = openssl_pkcs7_sign("TRA.xml", "TRA.tmp", "file://" . CERT, array("file://" . PRIVATEKEY, PASSPHRASE), array(), !PKCS7_DETACHED);
    if (!$STATUS) {
        exit("ERROR generating PKCS#7 signature\n");
    }
    $inf = fopen("TRA.tmp", "r");
    $i = 0;
    $CMS = "";
    while (!feof($inf)) {
        $buffer = fgets($inf);
        if ($i++ >= 4) {
            $CMS .= $buffer;
        }
    }
    fclose($inf);
    unlink("TRA.tmp");
    return $CMS;
}
开发者ID:aabcehmt,项目名称:fe,代码行数:19,代码来源:factura.php

示例5: sign_TRA

 private function sign_TRA()
 {
     $STATUS = openssl_pkcs7_sign($this->path . "xmlgenerados/TRA.xml", $this->path . "xmlgenerados/TRA.tmp", "file://" . $this->path . self::CERT, array("file://" . $this->path . self::PRIVATEKEY, self::PASSPHRASE), array(), !PKCS7_DETACHED);
     if (!$STATUS) {
         throw new Exception("ERROR generating PKCS#7 signature");
     }
     $inf = fopen($this->path . "xmlgenerados/TRA.tmp", "r");
     $i = 0;
     $CMS = "";
     while (!feof($inf)) {
         $buffer = fgets($inf);
         if ($i++ >= 4) {
             $CMS .= $buffer;
         }
     }
     fclose($inf);
     //unlink("TRA.xml");
     unlink($this->path . "xmlgenerados/TRA.tmp");
     return $CMS;
 }
开发者ID:sdepietro,项目名称:facturaElectronicaArgentina,代码行数:20,代码来源:wsaa.class.php

示例6: SignTRA

 public static function SignTRA()
 {
     $STATUS = openssl_pkcs7_sign("TRA.xml", "TRA.tmp", "file://" . sfConfig::get('CERT'), array("file://" . sfConfig::get('PRIVATEKEY'), sfConfig::get('PASSPHRASE')), array(), !PKCS7_DETACHED);
     if (!$STATUS) {
         throw new WsaaException(0, "Error al intentar firmar el TRA");
     }
     $inf = fopen("TRA.tmp", "r");
     $i = 0;
     $CMS = "";
     while (!feof($inf)) {
         $buffer = fgets($inf);
         if ($i++ >= 4) {
             $CMS .= $buffer;
         }
     }
     fclose($inf);
     unlink("TRA.xml");
     unlink("TRA.tmp");
     return $CMS;
 }
开发者ID:lapuntasoft,项目名称:facturacionafip,代码行数:20,代码来源:wsaa-client.class.php

示例7: create_signature

function create_signature($package_dir, $cert_path, $cert_password)
{
    // Load the push notification certificate
    $pkcs12 = file_get_contents($cert_path);
    $certs = array();
    if (!openssl_pkcs12_read($pkcs12, $certs, $cert_password)) {
        return;
    }
    $signature_path = "{$package_dir}/signature";
    // Sign the manifest.json file with the private key from the certificate
    $cert_data = openssl_x509_read($certs['cert']);
    $private_key = openssl_pkey_get_private($certs['pkey'], $cert_password);
    openssl_pkcs7_sign("{$package_dir}/manifest.json", $signature_path, $cert_data, $private_key, array(), PKCS7_BINARY | PKCS7_DETACHED);
    // Convert the signature from PEM to DER
    $signature_pem = file_get_contents($signature_path);
    $matches = array();
    if (!preg_match('~Content-Disposition:[^\\n]+\\s*?([A-Za-z0-9+=/\\r\\n]+)\\s*?-----~', $signature_pem, $matches)) {
        return;
    }
    $signature_der = base64_decode($matches[1]);
    file_put_contents($signature_path, $signature_der);
}
开发者ID:jdbriaris,项目名称:azure-notificationhubs-samples,代码行数:22,代码来源:createPushPackage.php

示例8: 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

示例9: createPackageSignature

 /**
  * Creates a package signature using the given certificate and package directory.
  *
  * @param \JWage\APNS\Certificate $certificate
  * @param \JWage\APNS\Safari\Package $package
  *
  * @return string Path of signature
  */
 public function createPackageSignature(Certificate $certificate, Package $package)
 {
     $pkcs12 = $certificate->getCertificateString();
     $certPassword = $certificate->getPassword();
     $certs = array();
     if (!openssl_pkcs12_read($pkcs12, $certs, $certPassword)) {
         throw new RuntimeException('Failed to create signature.');
     }
     $signaturePath = sprintf('%s/signature', $package->getPackageDir());
     $manifestJsonPath = sprintf('%s/manifest.json', $package->getPackageDir());
     // Sign the manifest.json file with the private key from the certificate
     $certData = openssl_x509_read($certs['cert']);
     $privateKey = openssl_pkey_get_private($certs['pkey'], $certPassword);
     openssl_pkcs7_sign($manifestJsonPath, $signaturePath, $certData, $privateKey, array(), PKCS7_BINARY | PKCS7_DETACHED);
     // Convert the signature from PEM to DER
     $signaturePem = file_get_contents($signaturePath);
     $matches = array();
     if (!preg_match('~Content-Disposition:[^\\n]+\\s*?([A-Za-z0-9+=/\\r\\n]+)\\s*?-----~', $signaturePem, $matches)) {
         throw new ErrorException('Failed to extract content from signature pem.');
     }
     $signatureDer = base64_decode($matches[1]);
     file_put_contents($signaturePath, $signatureDer);
     return $signaturePath;
 }
开发者ID:arshdeep79,项目名称:php-apns,代码行数:32,代码来源:PackageSigner.php

示例10: CreateBody


//.........这里部分代码省略.........
             $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', '', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->AttachAll("inline", $this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
         case 'alt':
             $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->EndBoundary($this->boundary[1]);
             break;
         case 'alt_inline':
             $body .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->TextLine("--" . $this->boundary[1]);
             $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
             $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->AttachAll("inline", $this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->EndBoundary($this->boundary[1]);
             break;
         case 'alt_attach':
             $body .= $this->TextLine("--" . $this->boundary[1]);
             $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
             $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->EndBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
         case 'alt_inline_attach':
             $body .= $this->TextLine("--" . $this->boundary[1]);
             $body .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
             $body .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
             $body .= $this->EncodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->TextLine("--" . $this->boundary[2]);
             $body .= $this->HeaderLine('Content-Type', 'multipart/related;');
             $body .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
             $body .= $this->LE;
             $body .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->AttachAll("inline", $this->boundary[3]);
             $body .= $this->LE;
             $body .= $this->EndBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
         default:
             // catch case 'plain' and case ''
             $body .= $this->EncodeString($this->Body, $this->Encoding);
             break;
     }
     if ($this->IsError()) {
         $body = '';
     } elseif ($this->sign_key_file) {
         try {
             $file = tempnam('', 'mail');
             file_put_contents($file, $body);
             //TODO check this worked
             $signed = tempnam("", "signed");
             if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), NULL)) {
                 @unlink($file);
                 $body = file_get_contents($signed);
                 @unlink($signed);
             } else {
                 @unlink($file);
                 @unlink($signed);
                 throw new phpmailerException($this->Lang("signing") . openssl_error_string());
             }
         } catch (phpmailerException $e) {
             $body = '';
             if ($this->exceptions) {
                 throw $e;
             }
         }
     }
     return $body;
 }
开发者ID:H-1-N-1,项目名称:User,代码行数:101,代码来源:class.phpmailer.php

示例11: createBody


//.........这里部分代码省略.........
         case 'alt':
             $body .= $this->getBoundary($this->boundary[1], '', 'text/plain', '');
             $body .= $this->encodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->getBoundary($this->boundary[1], '', 'text/html', '');
             $body .= $this->encodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             if (!empty($this->Ical)) {
                 $body .= $this->getBoundary($this->boundary[1], '', 'text/calendar; method=REQUEST', '');
                 $body .= $this->encodeString($this->Ical, $this->Encoding);
                 $body .= $this->LE . $this->LE;
             }
             $body .= $this->endBoundary($this->boundary[1]);
             break;
         case 'alt_inline':
             $body .= $this->getBoundary($this->boundary[1], '', 'text/plain', '');
             $body .= $this->encodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/related;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], '', 'text/html', '');
             $body .= $this->encodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->attachAll('inline', $this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->endBoundary($this->boundary[1]);
             break;
         case 'alt_attach':
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], '', 'text/plain', '');
             $body .= $this->encodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->getBoundary($this->boundary[2], '', 'text/html', '');
             $body .= $this->encodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->endBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->attachAll('attachment', $this->boundary[1]);
             break;
         case 'alt_inline_attach':
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], '', 'text/plain', '');
             $body .= $this->encodeString($this->AltBody, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->textLine('--' . $this->boundary[2]);
             $body .= $this->headerLine('Content-Type', 'multipart/related;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[3], '', 'text/html', '');
             $body .= $this->encodeString($this->Body, $this->Encoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->attachAll('inline', $this->boundary[3]);
             $body .= $this->LE;
             $body .= $this->endBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->attachAll('attachment', $this->boundary[1]);
             break;
         default:
             // catch case 'plain' and case ''
             $body .= $this->encodeString($this->Body, $this->Encoding);
             break;
     }
     if ($this->isError()) {
         $body = '';
     } elseif ($this->sign_key_file) {
         try {
             if (!defined('PKCS7_TEXT')) {
                 throw new phpmailerException($this->lang('signing') . ' OpenSSL extension missing.');
             }
             //TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
             $file = tempnam(sys_get_temp_dir(), 'mail');
             file_put_contents($file, $body);
             //TODO check this worked
             $signed = tempnam(sys_get_temp_dir(), 'signed');
             if (@openssl_pkcs7_sign($file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null)) {
                 @unlink($file);
                 $body = file_get_contents($signed);
                 @unlink($signed);
             } else {
                 @unlink($file);
                 @unlink($signed);
                 throw new phpmailerException($this->lang('signing') . openssl_error_string());
             }
         } catch (phpmailerException $e) {
             $body = '';
             if ($this->exceptions) {
                 throw $e;
             }
         }
     }
     return $body;
 }
开发者ID:Toney,项目名称:xmcms,代码行数:101,代码来源:class.phpmailer.php

示例12: smime_sign_message

/**
 * To verify the signed message on the command line:
 *
 *  openssl smime -verify -in <msg file> \
 *                -CAfile /usr/share/geni-ch/CA/cacert.pem
 */
function smime_sign_message($message, $signer_cert = null, $signer_key = null)
{
    if (!is_null($signer_cert)) {
        $msg_file = writeDataToTempFile($message, "msg-");
        $out_file = tempnam(sys_get_temp_dir(), "smime-");
        $headers = null;
        $flags = PKCS7_DETACHED;
        $extracerts = writeDataToTempFile($signer_cert, "cert-");
        if (openssl_pkcs7_sign($msg_file, $out_file, $signer_cert, $signer_key, $headers, $flags, $extracerts)) {
            /* SUCCESS */
            smime_debug("smime_sign_message succeeded.");
            $message = file_get_contents($out_file);
        } else {
            /* FAILURE */
            error_log("smime_sign_message failed.");
        }
        unlink($msg_file);
        unlink($out_file);
        unlink($extracerts);
    }
    return $message;
}
开发者ID:ahelsing,项目名称:geni-portal,代码行数:28,代码来源:smime.php

示例13: test_openssl_pkcs7_sign

function test_openssl_pkcs7_sign()
{
    $privkey = openssl_pkey_new();
    VERIFY($privkey != null);
    $csr = openssl_csr_new(null, $privkey);
    VERIFY($csr != null);
    $scert = openssl_csr_sign($csr, null, $privkey, 365);
    $pubkey = openssl_csr_get_public_key($csr);
    VERIFY($pubkey != null);
    $data = "some secret data";
    $infile = tempnam('/tmp', 'invmtestopenssl');
    $outfile = tempnam('/tmp', 'outvmtestopenssl');
    unlink($infile);
    unlink($outfile);
    file_put_contents($infile, $data);
    VERIFY(openssl_pkcs7_sign($infile, $outfile, $scert, $privkey, array("To" => "t@facebook.com", "From" => "hzhao@facebook.com")));
    $tmp = tempnam('/tmp', 'x509vmtestopenssl');
    unlink($tmp);
    VS(file_get_contents($tmp), false);
    VERIFY(openssl_x509_export_to_file($scert, $tmp));
    VS(openssl_pkcs7_verify($outfile, 0, $infile, (array) $tmp), true);
    unlink($infile);
    unlink($outfile);
    unlink($tmp);
}
开发者ID:ezoic,项目名称:hhvm,代码行数:25,代码来源:ext_openssl.php

示例14: CreateBody


//.........这里部分代码省略.........
         case 'inline_attach':
             $result .= $this->TextLine("--" . $this->boundary[1]);
             $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
             $result .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $result .= $this->LE;
             $result .= $this->GetBoundary($this->boundary[2], '', '', '');
             $result .= $this->EncodeString($this->Body, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->AttachAll("inline", $this->boundary[2]);
             $result .= $this->LE;
             $result .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
         case 'alt':
             $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
             $result .= $this->EncodeString($this->AltBody, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
             $result .= $this->EncodeString($this->Body, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->EndBoundary($this->boundary[1]);
             break;
         case 'alt_inline':
             $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
             $result .= $this->EncodeString($this->AltBody, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->TextLine("--" . $this->boundary[1]);
             $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
             $result .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $result .= $this->LE;
             $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
             $result .= $this->EncodeString($this->Body, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->AttachAll("inline", $this->boundary[2]);
             $result .= $this->LE;
             $result .= $this->EndBoundary($this->boundary[1]);
             break;
         case 'alt_attach':
             $result .= $this->TextLine("--" . $this->boundary[1]);
             $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
             $result .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $result .= $this->LE;
             $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
             $result .= $this->EncodeString($this->AltBody, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '');
             $result .= $this->EncodeString($this->Body, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->EndBoundary($this->boundary[2]);
             $result .= $this->LE;
             $result .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
         case 'alt_inline_attach':
             $result .= $this->TextLine("--" . $this->boundary[1]);
             $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
             $result .= $this->TextLine("\tboundary=\"" . $this->boundary[2] . '"');
             $result .= $this->LE;
             $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '');
             $result .= $this->EncodeString($this->AltBody, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->TextLine("--" . $this->boundary[2]);
             $result .= $this->HeaderLine('Content-Type', 'multipart/related;');
             $result .= $this->TextLine("\tboundary=\"" . $this->boundary[3] . '"');
             $result .= $this->LE;
             $result .= $this->GetBoundary($this->boundary[3], '', 'text/html', '');
             $result .= $this->EncodeString($this->Body, $this->Encoding);
             $result .= $this->LE . $this->LE;
             $result .= $this->AttachAll("inline", $this->boundary[3]);
             $result .= $this->LE;
             $result .= $this->EndBoundary($this->boundary[2]);
             $result .= $this->LE;
             $result .= $this->AttachAll("attachment", $this->boundary[1]);
             break;
     }
     if ($this->IsError()) {
         $result = '';
     } else {
         if ($this->sign_key_file) {
             $file = tempnam("", "mail");
             $fp = fopen($file, "w");
             fwrite($fp, $result);
             fclose($fp);
             $signed = tempnam("", "signed");
             if (@openssl_pkcs7_sign($file, $signed, "file://" . $this->sign_cert_file, array("file://" . $this->sign_key_file, $this->sign_key_pass), null)) {
                 $fp = fopen($signed, "r");
                 $result = fread($fp, filesize($this->sign_key_file));
                 $result = '';
                 while (!feof($fp)) {
                     $result = $result . fread($fp, 1024);
                 }
                 fclose($fp);
             } else {
                 $this->SetError('signing', openssl_error_string());
                 $result = '';
             }
             unlink($file);
             unlink($signed);
         }
     }
     return $result;
 }
开发者ID:duboisGeof,项目名称:deliciousMeals,代码行数:101,代码来源:class.phpmailer.php

示例15: createBody


//.........这里部分代码省略.........
         case 'alt_inline':
             $body .= $mimepre;
             $body .= $this->getBoundary($this->boundary[1], $altBodyCharSet, 'text/plain', $altBodyEncoding);
             $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/related;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
             $body .= $this->encodeString($this->Body, $bodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->attachAll('inline', $this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->endBoundary($this->boundary[1]);
             break;
         case 'alt_attach':
             $body .= $mimepre;
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
             $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, 'text/html', $bodyEncoding);
             $body .= $this->encodeString($this->Body, $bodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->endBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->attachAll('attachment', $this->boundary[1]);
             break;
         case 'alt_inline_attach':
             $body .= $mimepre;
             $body .= $this->textLine('--' . $this->boundary[1]);
             $body .= $this->headerLine('Content-Type', 'multipart/alternative;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, 'text/plain', $altBodyEncoding);
             $body .= $this->encodeString($this->AltBody, $altBodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->textLine('--' . $this->boundary[2]);
             $body .= $this->headerLine('Content-Type', 'multipart/related;');
             $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"');
             $body .= $this->LE;
             $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, 'text/html', $bodyEncoding);
             $body .= $this->encodeString($this->Body, $bodyEncoding);
             $body .= $this->LE . $this->LE;
             $body .= $this->attachAll('inline', $this->boundary[3]);
             $body .= $this->LE;
             $body .= $this->endBoundary($this->boundary[2]);
             $body .= $this->LE;
             $body .= $this->attachAll('attachment', $this->boundary[1]);
             break;
         default:
             // catch case 'plain' and case ''
             $body .= $this->encodeString($this->Body, $bodyEncoding);
             break;
     }
     if ($this->isError()) {
         $body = '';
     } elseif ($this->sign_key_file) {
         try {
             if (!defined('PKCS7_TEXT')) {
                 throw new phpmailerException($this->lang('extension_missing') . 'openssl');
             }
             // @TODO would be nice to use php://temp streams here, but need to wrap for PHP < 5.1
             $file = tempnam(sys_get_temp_dir(), 'mail');
             if (false === file_put_contents($file, $body)) {
                 throw new phpmailerException($this->lang('signing') . ' Could not write temp file');
             }
             $signed = tempnam(sys_get_temp_dir(), 'signed');
             //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197
             if (empty($this->sign_extracerts_file)) {
                 $sign = @openssl_pkcs7_sign($file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null);
             } else {
                 $sign = @openssl_pkcs7_sign($file, $signed, 'file://' . realpath($this->sign_cert_file), array('file://' . realpath($this->sign_key_file), $this->sign_key_pass), null, PKCS7_DETACHED, $this->sign_extracerts_file);
             }
             if ($sign) {
                 @unlink($file);
                 $body = file_get_contents($signed);
                 @unlink($signed);
                 //The message returned by openssl contains both headers and body, so need to split them up
                 $parts = explode("\n\n", $body, 2);
                 $this->MIMEHeader .= $parts[0] . $this->LE . $this->LE;
                 $body = $parts[1];
             } else {
                 @unlink($file);
                 @unlink($signed);
                 throw new phpmailerException($this->lang('signing') . openssl_error_string());
             }
         } catch (phpmailerException $exc) {
             $body = '';
             if ($this->exceptions) {
                 throw $exc;
             }
         }
     }
     return $body;
 }
开发者ID:routenull0,项目名称:phpipam,代码行数:101,代码来源:class.phpmailer.php


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