當前位置: 首頁>>代碼示例>>PHP>>正文


PHP openssl_pkcs12_read函數代碼示例

本文整理匯總了PHP中openssl_pkcs12_read函數的典型用法代碼示例。如果您正苦於以下問題:PHP openssl_pkcs12_read函數的具體用法?PHP openssl_pkcs12_read怎麽用?PHP openssl_pkcs12_read使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了openssl_pkcs12_read函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: array

/** 
 * 
 array(3) {
  ["cert"]=>
  string(1334) "-----BEGIN CERTIFICATE-----
MIIDrTCCAxagAwIBAgIQWQK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----
"
  ["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


注:本文中的openssl_pkcs12_read函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。