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

PHP openssl_pkcs12_read函数代码示例

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

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



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

示例1: load

 /**
  * @param string $pkcs12
  * @param string $password
  *
  * @throws Exception
  */
 public function load($pkcs12, string $password = NULL)
 {
     if (is_null($pkcs12)) {
         return;
     }
     if ($pkcs12 instanceof File) {
         $pkcs12 = $pkcs12->getContent();
     }
     if ($pkcs12 instanceof SplFileInfo) {
         $pkcs12 = file_get_contents($pkcs12);
     }
     if (!openssl_pkcs12_read($pkcs12, $result, $password)) {
         throw new RuntimeException(OpenSSL::getLastError());
     }
     if (array_key_exists('cert', $result)) {
         $certificate = new Certificate($result['cert']);
         $this->setCertificate($certificate);
     }
     if (array_key_exists('pkey', $result)) {
         $privateKey = new PrivateKey($result['pkey']);
         $this->setPrivateKey($privateKey);
     }
     if (array_key_exists('extracerts', $result)) {
         $this->setChain($result['extracerts']);
     }
 }
开发者ID:blar,项目名称:openssl,代码行数:32,代码来源:Pkcs12.php


示例2: pkcs12Read

 /**
  * @param $p12buf
  * @param $p12cert
  * @param $password
  * @return array
  * @throws \Exception
  */
 private static function pkcs12Read($p12buf, array $p12cert, $password)
 {
     if (!openssl_pkcs12_read($p12buf, $p12cert, $password)) {
         throw new \RuntimeException("Invalid cert format or password.");
     }
     return $p12cert;
 }
开发者ID:ochi51,项目名称:cybozu-http,代码行数:14,代码来源:Pfx.php


示例3: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81QBKdyF0RY+djo
b3cR9I7+hurpqhJmQ7yuvAWe2xWc+YNTQ48FDJTogXlB
-----END RSA PRIVATE KEY-----
"
  ["extracerts"]=>
  array(0) {
  }
}
*/
function cfcasign_pkcs12($plainText)
{
    $p12cert = array();
    //①读取公匙文件内容:二进制数据
    $file = 'ceshi/test.pfx';
    //二进制文件
    $fd = fopen($file, 'r');
    //只读模式打开文件
    $p12buf = fread($fd, filesize($file));
    //读取文件
    fclose($fd);
    /**
     * bool openssl_pkcs12_read ( string $pkcs12 , array &$certs , string $pass  )
     * 把以公匙加密标准证书存放区($pkcs12)转为数组存储($certs)
     * $pass:解开公匙加密标准证书存放区加密的密码
     */
    //②转为数组
    openssl_pkcs12_read($p12buf, $p12cert, 'cfca1234');
    $pkeyid = $p12cert["pkey"];
    $binary_signature = "";
    /**
     * bool openssl_sign ( string $data , string &$signature , mixed $priv_key_id [, int $signature_alg = OPENSSL_ALGO_SHA1 ] )
     * 生成签名
     * $data:特殊数据
     * $signature:如果成功,生成的签名(二进制数)
     * $priv_key_id:用于加密sha散列法生成的数据
     * 注意:$data没被加密过
     */
    openssl_sign($plainText, $binary_signature, $pkeyid, OPENSSL_ALGO_SHA1);
    return bin2hex($binary_signature);
    //将二进制数据转换成十六进制表示
}
开发者ID:licailing,项目名称:licailing,代码行数:81,代码来源:openssl.php


示例4: getClient

 /**
  * @param \Scalr_Environment $environment             Scalr Environment object
  * @param array              $config        optional  Config array
  * @return \Google_Service_Compute
  */
 public function getClient(\Scalr_Environment $environment = null, array $config = [])
 {
     $ccProps = null;
     if (empty($config)) {
         $ccProps = $environment->keychain(\SERVER_PLATFORMS::GCE)->properties;
         $config = $ccProps;
     }
     $client = new \Google_Client();
     $client->setApplicationName("Scalr GCE");
     $client->setScopes(array('https://www.googleapis.com/auth/compute'));
     $key = base64_decode($config[Entity\CloudCredentialsProperty::GCE_KEY]);
     // If it's not a json key we need to convert PKCS12 to PEM
     if (!$config[Entity\CloudCredentialsProperty::GCE_JSON_KEY]) {
         @openssl_pkcs12_read($key, $certs, 'notasecret');
         $key = $certs['pkey'];
     }
     $client->setAuthConfig(['type' => 'service_account', 'project_id' => $config[Entity\CloudCredentialsProperty::GCE_PROJECT_ID], 'private_key' => $key, 'client_email' => $config[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME], 'client_id' => $config[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]]);
     $client->setClientId($config[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]);
     $gce = new \Google_Service_Compute($client);
     //**** Store access token ****//
     $jsonAccessToken = $config[Entity\CloudCredentialsProperty::GCE_ACCESS_TOKEN];
     $accessToken = @json_decode($jsonAccessToken);
     if ($accessToken && $accessToken->created + $accessToken->expires_in > time()) {
         $client->setAccessToken($jsonAccessToken);
     } else {
         $gce->zones->listZones($config[Entity\CloudCredentialsProperty::GCE_PROJECT_ID]);
         if ($ccProps) {
             $token = $client->getAccessToken();
             $ccProps[Entity\CloudCredentialsProperty::GCE_ACCESS_TOKEN] = $token;
             $ccProps->save();
         }
     }
     return $gce;
 }
开发者ID:scalr,项目名称:scalr,代码行数:39,代码来源:GoogleCEPlatformModule.php


示例5: generateSignedJWT

 protected function generateSignedJWT()
 {
     if (!file_exists($this->privateKey) || !is_file($this->privateKey)) {
         throw new Exception('Private key does not exist');
     }
     $header = array('alg' => 'RS256', 'typ' => 'JWT');
     $t = time();
     $params = array('iss' => $this->email, 'scope' => Oauth::SCOPE_URL, 'aud' => Oauth::TOKEN_URL, 'exp' => $t + self::MAX_LIFETIME_SECONDS, 'iat' => $t);
     $encodings = array(base64_encode(json_encode($header)), base64_encode(json_encode($params)));
     $input = implode('.', $encodings);
     $certs = array();
     $pkcs12 = file_get_contents($this->privateKey);
     if (!openssl_pkcs12_read($pkcs12, $certs, $this->password)) {
         throw new Exception('Could not parse .p12 file');
     }
     if (!isset($certs['pkey'])) {
         throw new Exception('Could not find private key in .p12 file');
     }
     $keyId = openssl_pkey_get_private($certs['pkey']);
     if (!openssl_sign($input, $sig, $keyId, 'sha256')) {
         throw new Exception('Could not sign data');
     }
     $encodings[] = base64_encode($sig);
     $jwt = implode('.', $encodings);
     return $jwt;
 }
开发者ID:shahariaazam,项目名称:google-analytics-api-php,代码行数:26,代码来源:OauthService.php


示例6: __construct

 public function __construct($p12, $password)
 {
     if (!function_exists('openssl_x509_read')) {
         throw new Google_Exception('The Google PHP API library needs the openssl PHP extension');
     }
     // If the private key is provided directly, then this isn't in the p12
     // format. Different versions of openssl support different p12 formats
     // and the key from google wasn't being accepted by the version available
     // at the time.
     if (!$password && strpos($p12, "-----BEGIN RSA PRIVATE KEY-----") !== false) {
         $this->privateKey = openssl_pkey_get_private($p12);
     } elseif ($password === 'notasecret' && strpos($p12, "-----BEGIN PRIVATE KEY-----") !== false) {
         $this->privateKey = openssl_pkey_get_private($p12);
     } else {
         // This throws on error
         $certs = array();
         if (!openssl_pkcs12_read($p12, $certs, $password)) {
             throw new Google_Auth_Exception("Unable to parse the p12 file.  " . "Is this a .p12 file?  Is the password correct?  OpenSSL error: " . openssl_error_string());
         }
         // TODO(beaton): is this part of the contract for the openssl_pkcs12_read
         // method?  What happens if there are multiple private keys?  Do we care?
         if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
             throw new Google_Auth_Exception("No private key found in p12 file.");
         }
         $this->privateKey = openssl_pkey_get_private($certs['pkey']);
     }
     if (!$this->privateKey) {
         throw new Google_Auth_Exception("Unable to load private key");
     }
 }
开发者ID:learric,项目名称:Lightning100,代码行数:30,代码来源:P12.php


示例7: gal_service_account_upgrade

function gal_service_account_upgrade(&$option, $gal_option_name, &$existing_sa_options, $gal_sa_option_name)
{
    /* Convert ga_serviceemail ga_keyfilepath
     * into new separate sa options:
     * ga_sakey, ga_serviceemail, ga_pkey_print
     */
    if (count($existing_sa_options)) {
        return;
    }
    $existing_sa_options = array('ga_serviceemail' => isset($option['ga_serviceemail']) ? $option['ga_serviceemail'] : '', 'ga_sakey' => '', 'ga_pkey_print' => '<unspecified>');
    try {
        if (version_compare(PHP_VERSION, '5.3.0') >= 0 && function_exists('openssl_x509_read')) {
            if (isset($option['ga_keyfilepath']) && $option['ga_keyfilepath'] != '' && file_exists($option['ga_keyfilepath'])) {
                $p12key = @file_get_contents($option['ga_keyfilepath']);
                $certs = array();
                if (openssl_pkcs12_read($p12key, $certs, 'notasecret')) {
                    if (array_key_exists("pkey", $certs) && $certs["pkey"]) {
                        $privateKey = openssl_pkey_get_private($certs['pkey']);
                        $pemString = '';
                        if (openssl_pkey_export($privateKey, $pemString)) {
                            $existing_sa_options['ga_sakey'] = $pemString;
                        }
                        openssl_pkey_free($privateKey);
                        @unlink($options['ga_keyfilepath']);
                    }
                }
            }
        }
    } catch (Exception $e) {
        // Never mind
    }
    // Remove redundant parts of regular options
    unset($option['ga_serviceemail']);
    unset($option['ga_keyfilepath']);
}
开发者ID:Friends-School-Atlanta,项目名称:Deployable-WordPress,代码行数:35,代码来源:service_account_upgrade.php


示例8: validateEntity

 /**
  * @param   Entity\CloudCredentials $entity
  * @param   Entity\CloudCredentials $prevConfig
  *
  * @throws  ApiErrorException
  */
 public function validateEntity($entity, $prevConfig = null)
 {
     parent::validateEntity($entity, $prevConfig);
     $ccProps = $entity->properties;
     $prevCcProps = isset($prevConfig) ? $prevConfig->properties : null;
     if ($this->needValidation($ccProps, $prevCcProps)) {
         $ccProps[Entity\CloudCredentialsProperty::GCE_ACCESS_TOKEN] = "";
         try {
             $client = new \Google_Client();
             $client->setApplicationName("Scalr GCE");
             $client->setScopes(['https://www.googleapis.com/auth/compute']);
             $key = base64_decode($ccProps[Entity\CloudCredentialsProperty::GCE_KEY]);
             // If it's not a json key we need to convert PKCS12 to PEM
             if (!$ccProps[Entity\CloudCredentialsProperty::GCE_JSON_KEY]) {
                 @openssl_pkcs12_read($key, $certs, 'notasecret');
                 $key = $certs['pkey'];
             }
             $client->setAuthConfig(['type' => 'service_account', 'project_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID], 'private_key' => $key, 'client_email' => $ccProps[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME], 'client_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]]);
             $client->setClientId($ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]);
             $gce = new \Google_Service_Compute($client);
             $gce->zones->listZones($ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID]);
         } catch (Exception $e) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Provided GCE credentials are incorrect: ({$e->getMessage()})");
         }
         $entity->status = Entity\CloudCredentials::STATUS_ENABLED;
     }
 }
开发者ID:scalr,项目名称:scalr,代码行数:33,代码来源:GceCloudCredentialsAdapter.php


示例9: decryptPKCS12string

 /**
  * @return string A plaintext private key in PEM format
  *
  * @throws \Exception When the pkcs12 string cannot be decrypted
  */
 private function decryptPKCS12string()
 {
     $keystore = [];
     if (!@openssl_pkcs12_read($this->pkcs12string, $keystore, $this->passphrase)) {
         throw new \Exception('PKCS#12 cannot be decrypted');
     }
     return $keystore['pkey'];
 }
开发者ID:marcoshoya,项目名称:MasterpassBundle,代码行数:13,代码来源:EncryptedPrivateKey.php


示例10: read

 public function read()
 {
     $data = array();
     if (!openssl_pkcs12_read($this->content, $data, $this->password)) {
         throw new \Exception('O certificado não pode ser lido, senha ou arquivo inválido');
     }
     $this->certificate->setPubKey($data['cert']);
     $this->certificate->setPrivKey($data['pkey']);
 }
开发者ID:jefersonbelmiro,项目名称:php-digital-signer,代码行数:9,代码来源:PKCS12Reader.php


示例11: getPrivateKey

 /**
  * Method to retrieve the private key from the p12 file
  *
  * @return Private key string
  */
 private function getPrivateKey($masterPassData)
 {
     $thispath = dirname(__DIR__) . "/" . $masterPassData->keystorePath;
     $path = realpath($thispath);
     $keystore = array();
     $pkcs12 = file_get_contents($path);
     trim(openssl_pkcs12_read($pkcs12, $keystore, $masterPassData->keystorePassword));
     return $keystore['pkey'];
 }
开发者ID:luanmpereira,项目名称:default-store,代码行数:14,代码来源:MasterPassController.php


示例12: open

 /**
  * Abre um certificado enviado com a senha informada
  * @param  string $password A senha necessária para abrir o certificado
  * @return array  Com os dados extraidos do certificado
  * @throws CannotOpenCertificate Caso a senha do certificado for inválida
  * @since  1.0.0
  */
 public function open($password)
 {
     $key = file_get_contents($this->filePath);
     $dataCertificate = array();
     if (!openssl_pkcs12_read($key, $dataCertificate, $password)) {
         throw new CannotOpenCertificate($this->filePath);
     }
     return $dataCertificate;
 }
开发者ID:robmachado,项目名称:sped-gnre,代码行数:16,代码来源:CertificatePfxFileOperation.php


示例13: GetPrivate_Public_KeyFromPfxFile

 public function GetPrivate_Public_KeyFromPfxFile($filePath, $Passphase)
 {
     $p12cert = array();
     $fp = fopen($filePath, "r");
     $p12buf = fread($fp, filesize($filePath));
     fclose($fp);
     openssl_pkcs12_read($p12buf, $p12cert, $Passphase);
     $this->RsaPrivateKey = $p12cert['pkey'];
     $this->RsaPublicKey = $p12cert['cert'];
 }
开发者ID:Gouken,项目名称:WebMuApp,代码行数:10,代码来源:ClsCryptor.php


示例14: __construct

 /**
  * Represents a PKCS12 keystore.
  * @param string $contents The contents of the PKCS12 keystore.
  */
 public function __construct($contents, $passphrase)
 {
     if (!extension_loaded('openssl')) {
         throw new OpenSSLExtensionNotLoadedException('The openssl module is not loaded.');
     }
     if (!openssl_pkcs12_read($contents, $keystore, $passphrase)) {
         throw new KeyStoreDecryptionFailedException('Could not decrypt the certificate, the passphrase is incorrect, ' . 'its contents are mangled or it is not a valid PKCS #12 keystore.');
     }
     $this->X509Certificate = new X509Certificate($keystore['cert']);
     $this->privateKey = new PrivateKey($keystore['pkey']);
 }
开发者ID:ntthanh,项目名称:crypto,代码行数:15,代码来源:PKCS12.class.php


示例15: loadString

 /**
  * @param string $certificate
  * @param null|string $pass
  * @return bool
  * @throws Exception If could not open/parse certificate
  */
 public function loadString($certificate, $pass = null)
 {
     //unset cached certData
     //TODO: think Maybe disable loading of different certificate with some magic
     $this->certData = null;
     openssl_pkcs12_read($certificate, $this->raw_cert, $pass);
     if (!$this->raw_cert) {
         throw new Exception('Could not open certificate!');
     }
     return true;
 }
开发者ID:sokac237,项目名称:fiskalizacija-php,代码行数:17,代码来源:Certificate.php


示例16: cfcasign_pkcs12

 function cfcasign_pkcs12($plainText)
 {
     $p12cert = array();
     $file = $this->CICC_REAL['PFX_PATH'];
     $fd = fopen($file, 'r');
     $p12buf = fread($fd, filesize($file));
     fclose($fd);
     openssl_pkcs12_read($p12buf, $p12cert, $this->CICC_REAL['PFX_PASS']);
     $pkeyid = $p12cert["pkey"];
     $binary_signature = "";
     openssl_sign($plainText, $binary_signature, $pkeyid, OPENSSL_ALGO_SHA1);
     return bin2hex($binary_signature);
 }
开发者ID:ayaya118,项目名称:cicc,代码行数:13,代码来源:Payment.php


示例17: Certificate

 public function Certificate($path, $cert_password = '')
 {
     $this->path = $path;
     $this->cert_password = $cert_password;
     if (file_exists($this->path) == false) {
         return $this;
     }
     $pkcs12 = file_get_contents($this->path);
     if (openssl_pkcs12_read($pkcs12, $this->certs, $cert_password) == true) {
         $this->cert_data = openssl_x509_read($this->certs['cert']);
         $this->cert_info = openssl_x509_parse($this->cert_data);
     }
 }
开发者ID:rizumita,项目名称:PassCurrent,代码行数:13,代码来源:certificate.php


示例18: __construct

 /**
  * Archive creator for phar, tar, tgz and zip archives.
  *
  * @param string path to primary archive
  * @param string|false stub or false to use default stub of phar archives
  * @param int one of Phar::TAR, Phar::PHAR, or Phar::ZIP
  * @param int if the archive can be compressed (phar and tar), one of Phar::GZ, Phar::BZ2 or Phar::NONE
  *            for no compression
  * @param array an array of arrays containing information on additional archives to create.  The indices are:
  *
  *               0. extension (tar/tgz/zip)
  *               1. format (Phar::TAR, Phar::ZIP, Phar::PHAR)
  *               2. compression (Phar::GZ, Phar::BZ2, Phar::NONE)
  * @param string PKCS12 certificate to be used to sign the archive.  This must be a certificate issued
  *               by a certificate authority, self-signed certs will not be accepted by Pyrus
  * @param string passphrase, if any, for the PKCS12 certificate.
  */
 function __construct($path, $stub = false, $fileformat = \Phar::TAR, $compression = \Phar::GZ, array $others = null, $releaser = null, \PEAR2\Pyrus\Package $new = null, $pkcs12 = null, $passphrase = '')
 {
     if (!class_exists('Phar')) {
         throw new \PEAR2\Pyrus\Developer\Creator\Exception('Phar extension is not available');
     }
     if (!\Phar::canWrite() || !\Phar::isValidPharFilename($path, true)) {
         $this->_classname = 'PharData';
     }
     $this->path = $path;
     $this->compression = $compression;
     $this->format = $fileformat;
     $this->others = $others;
     $this->stub = $stub;
     if ($pkcs12 && !extension_loaded('openssl')) {
         throw new \PEAR2\Pyrus\Developer\Creator\Exception('Unable to use ' . 'OpenSSL signing of phars, enable the openssl PHP extension');
     }
     $this->pkcs12 = $pkcs12;
     $this->passphrase = $passphrase;
     if (null !== $this->pkcs12) {
         $cert = array();
         $pkcs = openssl_pkcs12_read(file_get_contents($this->pkcs12), $cert, $this->passphrase);
         if (!$pkcs) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('Unable to process openssl key');
         }
         $private = openssl_pkey_get_private($cert['pkey']);
         if (!$private) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('Unable to extract private openssl key');
         }
         $pub = openssl_pkey_get_public($cert['cert']);
         $info = openssl_x509_parse($cert['cert']);
         $details = openssl_pkey_get_details($pub);
         if (true !== openssl_x509_checkpurpose($cert['cert'], X509_PURPOSE_SSL_SERVER, \PEAR2\Pyrus\Channel\RemotePackage::authorities())) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('releasing maintainer\'s certificate is invalid');
         }
         // now verify that this cert is in fact the releasing maintainer's certificate
         // by verifying that alternate name is the releaser's email address
         if (!isset($info['subject']) || !isset($info['subject']['emailAddress'])) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('releasing maintainer\'s certificate does not contain' . ' an alternate name corresponding to the releaser\'s email address');
         }
         if ($info['subject']['emailAddress'] != $new->maintainer[$releaser]->email) {
             throw new \PEAR2\Pyrus\Developer\Creator\Exception('releasing maintainer\'s certificate ' . 'alternate name does not match the releaser\'s email address ' . $new->maintainer[$releaser]->email);
         }
         $pkey = '';
         openssl_pkey_export($private, $pkey);
         $this->x509cert = $cert['cert'];
         $this->publickey = $details['key'];
         $this->privatekey = $pkey;
     }
 }
开发者ID:rosstuck,项目名称:PEAR2_Pyrus,代码行数:66,代码来源:Phar.php


示例19: __construct

 /**
  * Construct
  *
  * @param String $certificate P12 file
  * @param String $passphrase  Passphrase for the certificate
  * @param bool   $path        The certificate variable is a path
  */
 function __construct($certificate, $passphrase = null, $path = true)
 {
     if ($path) {
         $this->certificate_path = $certificate;
         $certificate = file_get_contents($certificate);
         //Il est important que le certificat soit en p12
         openssl_pkcs12_read($certificate, $array_cert, $passphrase);
         $this->certificate = $array_cert["cert"];
         $this->pivate_key = $array_cert["pkey"];
         $this->chain = $array_cert["extracerts"];
     } else {
         $this->certificate = $certificate;
     }
     $this->passphrase = $passphrase;
 }
开发者ID:fbone,项目名称:mediboard4,代码行数:22,代码来源:CSSLCertificate.class.php


示例20: rsa_sign1

/**
 * 
 * [rsa_sign description]
 * @param  [string] $pfx  [pfx 证书]
 * @param  [string] $pwd  [pfx 密码]
 * @param  [string] $data [要加密的内容]
 * @return [string]       [description]
 */
function rsa_sign1($pfx, $pwd, $data)
{
    //1、使用密码读取证书
    openssl_pkcs12_read(file_get_contents($pfx), $cert_arr, $pwd);
    //2、验证证书是否在有效期内
    $cer = openssl_x509_parse($cert_arr['cert']);
    //3、取得密钥
    $pkey = openssl_get_privatekey($cert_arr['pkey']);
    $signature = '';
    $data = strval($data);
    if (!openssl_sign($data, $signature, $pkey, OPENSSL_ALGO_SHA1)) {
        return null;
    }
    $signature = base64_encode($signature);
    return $signature;
}
开发者ID:GEGEzhenweigege,项目名称:zanguish,代码行数:24,代码来源:sha1withrsa.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP openssl_pkcs7_encrypt函数代码示例发布时间:2022-05-15
下一篇:
PHP openssl_pkcs12_export函数代码示例发布时间: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