• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP openssl_x509_read函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: EncryptedPin

function EncryptedPin($sPin, $sCardNo, $sPubKeyURL)
{
    global $log;
    $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH, " ");
    /**
     * [WeEngine System] Copyright (c) 2014 WE7.CC
     * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
     */
    $fp = fopen($sPubKeyURL, "r");
    if ($fp != NULL) {
        $sCrt = fread($fp, 8192);
        fclose($fp);
    }
    $sPubCrt = openssl_x509_read($sCrt);
    if ($sPubCrt === FALSE) {
        print "openssl_x509_read in false!";
        return -1;
    }
    $sPubKey = openssl_x509_parse($sPubCrt);
    $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
    if ($sInput == 1) {
        print "Pin2PinBlockWithCardNO Error ! : " . $sInput;
        return 1;
    }
    $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
    if ($iRet === TRUE) {
        $sBase64EncodeOutData = base64_encode($sOutData);
        return $sBase64EncodeOutData;
    } else {
        print "openssl_public_encrypt Error !";
        return -1;
    }
}
开发者ID:hahamy,项目名称:we7,代码行数:33,代码来源:PublicEncrypte.php


示例2: make_request

 public function make_request()
 {
     $g = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
     set_error_handler(function () {
         return true;
     });
     $r = stream_socket_client("ssl://{$this->target}:{$this->target_port}", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
     restore_error_handler();
     if (!$r) {
         return true;
     } else {
         $cont = stream_context_get_params($r);
         $cert = openssl_x509_read($cont["options"]["ssl"]["peer_certificate"]);
         $cert_data = openssl_x509_parse($cert);
         openssl_x509_export($cert, $out, FALSE);
         $signature_algorithm = null;
         if (preg_match('/^\\s+Signature Algorithm:\\s*(.*)\\s*$/m', $out, $match)) {
             $signature_algorithm = $match[1];
         }
         $this->sha_type = $signature_algorithm;
         $this->common_name = $cert_data['subject']['CN'];
         $this->alternative_names = $cert_data['extensions']['subjectAltName'];
         $this->issuer = $cert_data['issuer']['O'];
         $this->valid_from = date('m-d-Y H:i:s', strval($cert_data['validFrom_time_t']));
         $this->valid_to = date('m-d-Y H:i:s', strval($cert_data['validTo_time_t']));
         $this->parse_alternative_names();
     }
 }
开发者ID:ryebell,项目名称:achilles,代码行数:28,代码来源:CheckSSL.php


示例3: webid_claim

function webid_claim()
{
    $r = array('uri' => array());
    if (isset($_SERVER['SSL_CLIENT_CERT'])) {
        $pem = $_SERVER['SSL_CLIENT_CERT'];
        if ($pem) {
            $x509 = openssl_x509_read($pem);
            $pubKey = openssl_pkey_get_public($x509);
            $keyData = openssl_pkey_get_details($pubKey);
            if (isset($keyData['rsa'])) {
                if (isset($keyData['rsa']['n'])) {
                    $r['m'] = strtolower(array_pop(unpack("H*", $keyData['rsa']['n'])));
                }
                if (isset($keyData['rsa']['e'])) {
                    $r['e'] = hexdec(array_shift(unpack("H*", $keyData['rsa']['e'])));
                }
            }
            $d = openssl_x509_parse($x509);
            if (isset($d['extensions']) && isset($d['extensions']['subjectAltName'])) {
                foreach (explode(', ', $d['extensions']['subjectAltName']) as $elt) {
                    if (substr($elt, 0, 4) == 'URI:') {
                        $r['uri'][] = substr($elt, 4);
                    }
                }
            }
        }
    }
    return $r;
}
开发者ID:sgml,项目名称:rww.io,代码行数:29,代码来源:webid.lib.php


示例4: getCertIdByCerPath

 protected static function getCertIdByCerPath($certPath)
 {
     $x509data = file_get_contents($certPath);
     openssl_x509_read($x509data);
     $certData = openssl_x509_parse($x509data);
     return $certData['serialNumber'];
 }
开发者ID:wyrover,项目名称:omnipay-unionpay,代码行数:7,代码来源:Helper.php


示例5: encryptedPin

 /**
  * 证书Id验证密码方法
  * @param $sPin
  * @param $sCardNo
  * @param array $options 参数数组
  * @return array
  */
 function encryptedPin($sPin, $sCardNo, $options)
 {
     $resArr = ['code' => 1];
     $fp = fopen($options['encrypt_cert_path'], "r");
     if ($fp != NULL) {
         $sCrt = fread($fp, 8192);
         fclose($fp);
         $sPubCrt = openssl_x509_read($sCrt);
         if ($sPubCrt === false) {
             $resArr['code'] = 2;
             $resArr['message'] = '读取密码加密证书数据失败';
         } else {
             $pinBlock = new UnionPayPinBlock();
             $sInput = $pinBlock->Pin2PinBlockWithCardNO($sPin, $sCardNo);
             if ($sInput['code'] > 0) {
                 $resArr['code'] = 3;
                 $resArr['message'] = $sInput['message'];
             } else {
                 $iRet = openssl_public_encrypt($sInput['data'], $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
                 if ($iRet === true) {
                     $resArr['data'] = base64_encode($sOutData);
                 } else {
                     $resArr['code'] = 3;
                     $resArr['message'] = '加密失败';
                 }
             }
         }
     } else {
         $resArr['code'] = 1;
         $resArr['message'] = '打开密码加密证书失败';
     }
     return $resArr;
 }
开发者ID:a07061625,项目名称:pay,代码行数:40,代码来源:UnionPayPublicEncrypt.php


示例6: EncryptedPin

function EncryptedPin($sPin, $sCardNo, $sPubKeyURL)
{
    global $log;
    $sPubKeyURL = trim(SDK_ENCRYPT_CERT_PATH, " ");
    $fp = fopen($sPubKeyURL, "r");
    if ($fp != NULL) {
        $sCrt = fread($fp, 8192);
        fclose($fp);
    }
    $sPubCrt = openssl_x509_read($sCrt);
    if ($sPubCrt === FALSE) {
        print "openssl_x509_read in false!";
        return -1;
    }
    $sPubKey = openssl_x509_parse($sPubCrt);
    $sInput = Pin2PinBlockWithCardNO($sPin, $sCardNo);
    if ($sInput == 1) {
        print "Pin2PinBlockWithCardNO Error ! : " . $sInput;
        return 1;
    }
    $iRet = openssl_public_encrypt($sInput, $sOutData, $sCrt, OPENSSL_PKCS1_PADDING);
    if ($iRet === TRUE) {
        $sBase64EncodeOutData = base64_encode($sOutData);
        return $sBase64EncodeOutData;
    } else {
        print "openssl_public_encrypt Error !";
        return -1;
    }
}
开发者ID:zhang19960118,项目名称:html11,代码行数:29,代码来源:PublicEncrypte.php


示例7: get_fingerprint

 /**
  * Get the fingerprint from the specified certificate
  *
  * @param string $certificate
  * @return fingerprint or null on failure
  */
 public static function get_fingerprint($certificate, $hash = null)
 {
     $fingerprint = null;
     // The openssl_x509_read() function will throw an warning if the supplied
     // parameter cannot be coerced into an X509 certificate
     // @codingStandardsIgnoreStart
     $resource = @openssl_x509_read($certificate);
     // @codingStandardsIgnoreEnd
     if (false !== $resource) {
         $output = null;
         $result = openssl_x509_export($resource, $output);
         if (false !== $result) {
             $output = str_replace(self::CERTIFICATE_BEGIN, '', $output);
             $output = str_replace(self::CERTIFICATE_END, '', $output);
             // Base64 decode
             $fingerprint = base64_decode($output);
             // Hash
             if (null !== $hash) {
                 $fingerprint = hash($hash, $fingerprint);
             }
         }
         // @todo else what to do?
     }
     // @todo else what to do?
     return $fingerprint;
 }
开发者ID:wp-pay-gateways,项目名称:ideal-advanced-v3,代码行数:32,代码来源:Security.php


示例8: setup

 public function setup()
 {
     $proxyServer = Phake::mock('EngineBlock_Corto_ProxyServer');
     $log = Phake::mock('Psr\\Log\\LoggerInterface');
     Phake::when($proxyServer)->getSessionLog()->thenReturn($log);
     Phake::when($proxyServer)->getSigningCertificates()->thenReturn(new EngineBlock_X509_KeyPair(new EngineBlock_X509_Certificate(openssl_x509_read(file_get_contents(__DIR__ . '/test.pem.crt'))), new EngineBlock_X509_PrivateKey(__DIR__ . '/test.pem.key')));
     $this->bindings = new EngineBlock_Corto_Module_Bindings($proxyServer);
 }
开发者ID:WebSpider,项目名称:OpenConext-engineblock,代码行数:8,代码来源:BindingsTest.php


示例9: getCertIdByCerPath

function getCertIdByCerPath($cert_path)
{
    $x509data = file_get_contents($cert_path);
    openssl_x509_read($x509data);
    $certdata = openssl_x509_parse($x509data);
    $cert_id = $certdata['serialNumber'];
    return $cert_id;
}
开发者ID:keycoolkui,项目名称:weixinfenxiao,代码行数:8,代码来源:secureUtil.php


示例10: fromString

 /**
  * Parse a given string as a X.509 certificate.
  *
  * @param string $x509CertificateContent
  * @return EngineBlock_X509_Certificate
  * @throws EngineBlock_Exception
  */
 public function fromString($x509CertificateContent)
 {
     $opensslCertificate = openssl_x509_read($x509CertificateContent);
     if (!$opensslCertificate) {
         throw new EngineBlock_Exception("Unable to read X.509 certificate from content: '{$x509CertificateContent}'");
     }
     return new EngineBlock_X509_Certificate($opensslCertificate);
 }
开发者ID:WebSpider,项目名称:OpenConext-engineblock,代码行数:15,代码来源:CertificateFactory.php


示例11: rsa_verify2

/**
 * 验签 方法 二 (未知公匙,获得需经转换)
 * [rsa_verify2 description]
 * @param  [type] $cert_file [description]
 * @param  [type] $data      [description]
 * @param  [type] $signature [description]
 * @return [type]            [description]
 */
function rsa_verify2($cert_file, $data, $signature)
{
    $cert = der2pem(file_get_contents($cert_file));
    $certs = openssl_x509_read($cert);
    $key = openssl_get_publickey($certs);
    $result = (bool) openssl_verify($data, base64_decode($signature), $key, OPENSSL_ALGO_SHA1);
    openssl_free_key($key);
    return $result;
}
开发者ID:GEGEzhenweigege,项目名称:zanguish,代码行数:17,代码来源:sha1withrsa.php


示例12: validateSslOptions

 /**
  * @return bool
  */
 protected function validateSslOptions()
 {
     // Get the contents.
     if (!is_readable($this->certPath)) {
         $this->stdErr->writeln("The certificate file could not be read: " . $this->certPath);
         return false;
     }
     $sslCert = trim(file_get_contents($this->certPath));
     // Do a bit of validation.
     $certResource = openssl_x509_read($sslCert);
     if (!$certResource) {
         $this->stdErr->writeln("The certificate file is not a valid X509 certificate: " . $this->certPath);
         return false;
     }
     // Then the key. Does it match?
     if (!is_readable($this->keyPath)) {
         $this->stdErr->writeln("The private key file could not be read: " . $this->keyPath);
         return false;
     }
     $sslPrivateKey = trim(file_get_contents($this->keyPath));
     $keyResource = openssl_pkey_get_private($sslPrivateKey);
     if (!$keyResource) {
         $this->stdErr->writeln("Private key not valid, or passphrase-protected: " . $this->keyPath);
         return false;
     }
     $keyMatch = openssl_x509_check_private_key($certResource, $keyResource);
     if (!$keyMatch) {
         $this->stdErr->writeln("The provided certificate does not match the provided private key.");
         return false;
     }
     // Each chain needs to contain one or more valid certificates.
     $chainFileContents = $this->readChainFiles($this->chainPaths);
     foreach ($chainFileContents as $filePath => $data) {
         $chainResource = openssl_x509_read($data);
         if (!$chainResource) {
             $this->stdErr->writeln("File contains an invalid X509 certificate: " . $filePath);
             return false;
         }
         openssl_x509_free($chainResource);
     }
     // Split up the chain file contents.
     $chain = [];
     $begin = '-----BEGIN CERTIFICATE-----';
     foreach ($chainFileContents as $data) {
         if (substr_count($data, $begin) > 1) {
             foreach (explode($begin, $data) as $cert) {
                 $chain[] = $begin . $cert;
             }
         } else {
             $chain[] = $data;
         }
     }
     // Yay we win.
     $this->sslOptions = ['certificate' => $sslCert, 'key' => $sslPrivateKey, 'chain' => $chain];
     return true;
 }
开发者ID:commerceguys,项目名称:platform-cli,代码行数:59,代码来源:DomainCommandBase.php


示例13: cert_signature_algorithm

function cert_signature_algorithm($raw_cert_data)
{
    $cert_read = openssl_x509_read($raw_cert_data);
    openssl_x509_export($cert_read, $out, FALSE);
    $signature_algorithm = null;
    if (preg_match('/^\\s+Signature Algorithm:\\s*(.*)\\s*$/m', $out, $match)) {
        $signature_algorithm = $match[1];
    }
    return $signature_algorithm;
}
开发者ID:ntthanh,项目名称:ssl-decoder,代码行数:10,代码来源:verify_certifitcate.php


示例14: calculateThumbprint

 public static function calculateThumbprint($certificate, $hash)
 {
     if (function_exists('openssl_x509_fingerprint')) {
         $cert = openssl_x509_read($certificate);
         return openssl_x509_fingerprint($cert, $hash);
     }
     $cert = preg_replace('#-.*-|\\r|\\n#', '', $certificate);
     $bin = base64_decode($cert);
     return hash($hash, $bin);
 }
开发者ID:rwx-zwx-awx,项目名称:jose,代码行数:10,代码来源:X509Thumbprint.php


示例15: __construct

 /**
  * Constructs a verifier from the supplied PEM-encoded certificate.
  *
  * $pem: a PEM encoded certificate (not a file).
  * @param $pem
  * @throws Google_AuthException
  * @throws Google_Exception
  */
 function __construct($pem)
 {
     if (!function_exists('openssl_x509_read')) {
         throw new Google_Exception('Google API PHP client needs the openssl PHP extension');
     }
     $this->publicKey = openssl_x509_read($pem);
     if (!$this->publicKey) {
         throw new Google_AuthException("Unable to parse PEM: {$pem}");
     }
 }
开发者ID:johngrange,项目名称:wookeyholeweb,代码行数:18,代码来源:Google_PemVerifier.php


示例16: __construct

 /**
  * Constructs a verifier from the supplied PEM-encoded certificate.
  *
  * $pem: a PEM encoded certificate (not a file).
  */
 function __construct($pem)
 {
     if (!function_exists('openssl_x509_read')) {
         throw new Exception('The Google PHP API library needs the openssl PHP extension');
     }
     $this->publicKey = openssl_x509_read($pem);
     if (!$this->publicKey) {
         throw new apiAuthException("Unable to parse PEM: {$pem}");
     }
 }
开发者ID:joshquila,项目名称:demo2-youse,代码行数:15,代码来源:apiPemVerifier.php


示例17: validateCert

 private function validateCert($cert)
 {
     $data = openssl_x509_read($cert);
     $certData = openssl_x509_parse($data);
     $certValidDate = gmmktime(0, 0, 0, substr($certData['validTo'], 2, 2), substr($certData['validTo'], 4, 2), substr($certData['validTo'], 0, 2));
     if ($certValidDate < time()) {
         error_log(__METHOD__ . ': Certificate expired in ' . date('Y-m-d', $certValidDate));
         return false;
     }
     return true;
 }
开发者ID:reinaldons,项目名称:NFePHPaulista,代码行数:11,代码来源:NFe.class.php


示例18: verifySign

 /**
  * 验证签名
  * @method verifySign
  * @since 0.0.1
  * @return {boolean}
  * @example $this->verifySign();
  */
 public function verifySign()
 {
     if (empty($_POST) || !isset($_POST['Plain']) || !isset($_POST['Signature'])) {
         return false;
     }
     $cer = file_get_contents(\Yii::getAlias($this->verifyCertPath));
     $_cer = openssl_x509_read($cer);
     $pkey = openssl_get_publickey($_cer);
     $result = openssl_verify($_POST['Plain'], hex2bin($_POST['Signature']), $pkey, OPENSSL_ALGO_MD5);
     openssl_free_key($pkey);
     return $result;
 }
开发者ID:pointdnd,项目名称:yii2-payment,代码行数:19,代码来源:Psbc.php


示例19: setPayPalCertificate

 /**
  * Sets the PayPal certificate
  *
  * @param mixed $fileName - The path to the PayPal certificate.
  * @return bollean TRUE if the certificate is read successfully, FALSE otherwise.
  */
 public function setPayPalCertificate($fileName)
 {
     if (is_readable($fileName)) {
         $certificate = openssl_x509_read(file_get_contents($fileName));
         if ($certificate !== FALSE) {
             $this->paypalCertificate = $certificate;
             $this->paypalCertificateFile = $fileName;
             return TRUE;
         }
     }
     return FALSE;
 }
开发者ID:jmiridis,项目名称:atcsf1,代码行数:18,代码来源:esPaypalEncryptor.class.php


示例20: __construct

 public function __construct($pem)
 {
     if (!is_string($pem)) {
         throw new \InvalidArgumentException("Invalid variable type: Expected string, got " . gettype($pem));
     }
     if (!($cert = @openssl_x509_read($pem))) {
         throw new InvalidCertificateException("Invalid PEM encoded certificate!");
     }
     $this->pem = $pem;
     if (!($this->info = openssl_x509_parse($cert))) {
         throw new InvalidCertificateException("Invalid PEM encoded certificate!");
     }
 }
开发者ID:kelunik,项目名称:certificate,代码行数:13,代码来源:Certificate.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP opentab函数代码示例发布时间:2022-05-15
下一篇:
PHP openssl_x509_parse函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap