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


PHP openssl_pkey_free函数代码示例

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


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

示例1: generate

 /**
  * Generates a new key pair with the given length in bits.
  *
  * @api
  * @param int $bits length of the key
  * @return KeyPair generated key pair
  */
 public function generate($bits = 2048)
 {
     if (!is_int($bits)) {
         throw new \InvalidArgumentException(sprintf("\$bits must be of type int, %s given", gettype($bits)));
     }
     if ($bits < 2048) {
         throw new \InvalidArgumentException("Keys with fewer than 2048 bits are not allowed!");
     }
     $configFile = $defaultConfigFile = __DIR__ . "/../res/openssl.cnf";
     if (class_exists("Phar") && !empty(Phar::running(true))) {
         $configContent = file_get_contents($configFile);
         $configFile = tempnam(sys_get_temp_dir(), "acme_openssl_");
         file_put_contents($configFile, $configContent);
         register_shutdown_function(function () use($configFile) {
             @unlink($configFile);
         });
     }
     $res = openssl_pkey_new(["private_key_type" => OPENSSL_KEYTYPE_RSA, "private_key_bits" => $bits, "config" => $configFile]);
     $success = openssl_pkey_export($res, $privateKey, null, ["config" => $configFile]);
     if ($configFile !== $defaultConfigFile) {
         @unlink($configFile);
     }
     if (!$success) {
         openssl_pkey_free($res);
         throw new \RuntimeException("Key export failed!");
     }
     $publicKey = openssl_pkey_get_details($res)["key"];
     openssl_pkey_free($res);
     // clear error buffer, because of minimalistic openssl.cnf
     while (openssl_error_string() !== false) {
     }
     return new KeyPair($privateKey, $publicKey);
 }
开发者ID:kelunik,项目名称:acme,代码行数:40,代码来源:OpenSSLKeyGenerator.php

示例2: generateKeys

 /**
  * Generate public and private key
  * @param array $options
  */
 public function generateKeys(array $options = self::DEFAULT_PUBLIC_KEY_OPTIONS)
 {
     $keys = openssl_pkey_new($options);
     $this->publicKey = openssl_pkey_get_details($keys)["key"];
     openssl_pkey_export($keys, $this->privateKey);
     openssl_pkey_free($keys);
 }
开发者ID:ezimuel,项目名称:phpcrypto,代码行数:11,代码来源:PublicKey.php

示例3: free

 /**
  * Frees the resource associated with this private key.
  * This is automatically done on destruct.
  */
 private function free()
 {
     if ($this->keyResource) {
         openssl_pkey_free($this->keyResource);
     }
     $this->keyResource = null;
 }
开发者ID:ntthanh,项目名称:crypto,代码行数:11,代码来源:PrivateKey.class.php

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

示例5: rsa_decrypt

 function rsa_decrypt($ciphertext, $private_key, $password)
 {
     // 암호문을 base64로 디코딩한다.
     $ciphertext = @base64_decode($ciphertext, true);
     if ($ciphertext === false) {
         return false;
     }
     // 개인키를 사용하여 복호화한다.
     $privkey_decoded = @openssl_pkey_get_private($private_key, $password);
     if ($privkey_decoded === false) {
         return false;
     }
     $plaintext = false;
     $status = @openssl_private_decrypt($ciphertext, $plaintext, $privkey_decoded);
     @openssl_pkey_free($privkey_decoded);
     if (!$status || $plaintext === false) {
         return false;
     }
     // 압축을 해제하여 평문을 얻는다.
     $plaintext = @gzuncompress($plaintext);
     if ($plaintext === false) {
         return false;
     }
     // 이상이 없는 경우 평문을 반환한다.
     return $plaintext;
 }
开发者ID:mclkim,项目名称:kaiser,代码行数:26,代码来源:rsaCrypt.php

示例6: __destruct

 public function __destruct()
 {
     if (!is_resource($this->handle)) {
         return;
     }
     openssl_pkey_free($this->handle);
 }
开发者ID:blar,项目名称:openssl,代码行数:7,代码来源:Key.php

示例7: removeAll

 public function removeAll()
 {
     foreach ($this->resources as $resource) {
         openssl_pkey_free($resource);
     }
     $this->keys = array();
     $this->resources = array();
 }
开发者ID:charlycoste,项目名称:openssl,代码行数:8,代码来源:PKeyFactory.php

示例8: generateKeyPair

 /**
  * Generate a key pair (public / private key) with optional passphrase
  * that protects the private key.
  *
  * @param string $passphrase
  * @return KeyPair
  */
 public function generateKeyPair($passphrase = null)
 {
     $privateKey = null;
     $encrypted = $passphrase !== null;
     $keyPair = openssl_pkey_new();
     openssl_pkey_export($keyPair, $privateKey, $passphrase);
     $keyDetails = openssl_pkey_get_details($keyPair);
     $publicKey = $keyDetails['key'];
     openssl_pkey_free($keyPair);
     return new KeyPair($privateKey, $publicKey, $encrypted);
 }
开发者ID:SomeBdyElse,项目名称:Surf,代码行数:18,代码来源:OpenSslEncryptionService.php

示例9: generateKeyPair

 /**
  * Generate a key pair (public / private key) with optional passphrase
  * that protects the private key.
  *
  * @param string $passphrase
  * @return \TYPO3\Deploy\Encryption\KeyPair
  * @author Christopher Hlubek <hlubek@networkteam.com>
  */
 public function generateKeyPair($passphrase = NULL)
 {
     $privateKey = NULL;
     $encrypted = $passphrase !== NULL;
     $keyPair = openssl_pkey_new();
     openssl_pkey_export($keyPair, $privateKey, $passphrase);
     $keyDetails = openssl_pkey_get_details($keyPair);
     $publicKey = $keyDetails['key'];
     openssl_pkey_free($keyPair);
     return new \TYPO3\Deploy\Encryption\KeyPair($privateKey, $publicKey, $encrypted);
 }
开发者ID:hlubek,项目名称:Deploy-Package,代码行数:19,代码来源:OpenSslEncryptionService.php

示例10: hasSigned

 /**
  * @param Signature $signature
  *
  * @return boolean Whether the signature has been signed by this certificate
  */
 public function hasSigned(Signature $signature)
 {
     $key = openssl_pkey_get_public($this->x509Cert);
     try {
         $hasSigned = $signature->isSignedByKey($key);
     } catch (\Excetpion $e) {
         openssl_pkey_free($key);
         throw $e;
     }
     openssl_pkey_free($key);
     return $hasSigned;
 }
开发者ID:kgilden,项目名称:php-digidoc,代码行数:17,代码来源:Cert.php

示例11: base64_signature

 /**
  * Sign a string using the configured private key
  *
  * @param string $str  The string to calculate a signature for
  */
 private function base64_signature($str)
 {
     $key = openssl_pkey_get_private($this->private_key);
     if ($key === false) {
         throw new SimpleSAML_Error_Exception("Unable to load private key: " . openssl_error_string());
     }
     if (!openssl_sign($str, $sig, $key)) {
         throw new SimpleSAML_Error_Exception("Unable to create signature: " . openssl_error_string());
     }
     openssl_pkey_free($key);
     return base64_encode($sig);
 }
开发者ID:jstormes,项目名称:simplesamlphp,代码行数:17,代码来源:aselect.php

示例12: load

 protected function load()
 {
     if (false == is_file($this->filename)) {
         throw new \RuntimeException(sprintf("Specified private key file '%s' does not exist", $this->filename));
     }
     $this->loadedContent = file_get_contents($this->filename);
     $resource = openssl_pkey_get_private($this->loadedContent);
     if (false == $resource) {
         $this->loadedContent = null;
         throw new \RuntimeException(sprintf("Specified private key '%s' is invalid", $this->filename));
     }
     openssl_pkey_free($resource);
 }
开发者ID:appsco,项目名称:market-api,代码行数:13,代码来源:PrivateKeyFileProvider.php

示例13: generateKeypair

 /**
  * Function to generate a new RSA keypair. This is not
  * used for point derivation or for generating signatures.
  * Only used for assymetric data encryption, as needed.
  *
  * @param int
  * @param string
  * @return array|boolean array of keys on success, boolean false on failure
  */
 public final function generateKeypair($keybits = 512, $digest_alg = 'sha512')
 {
     try {
         /* see: http://www.php.net/manual/en/function.openssl-pkey-new.php */
         if (function_exists('openssl_pkey_new')) {
             $keypair = array();
             /* openssl keysize can't be smaller than 384 bits */
             if ((int) $keybits < 384) {
                 $keybits = 384;
             }
             if (!isset($digest_alg) || trim($digest_alg) == '') {
                 $digest_alg = 'sha512';
             }
             /*
              * RSA is the only supported key type at this time
              * http://www.php.net/manual/en/function.openssl-csr-new.php
              */
             $config = array('digest_alg' => $digest_alg, 'private_key_bits' => (int) $keybits, 'private_key_type' => OPENSSL_KEYTYPE_RSA);
             $resource = openssl_pkey_new($config);
             if (!$resource) {
                 throw new \Exception('Error in generateOpenSSLKeypair: Could not create new OpenSSL resource.');
                 /* with the openssl extension, you also have it's own errors returned */
                 while ($msg = openssl_error_string()) {
                     throw new \Exception('Error in generateOpenSSLKeypair: OpenSSL reported error: ' . $msg);
                 }
                 return false;
             }
             if (openssl_pkey_export($resource, $keypair['pri'])) {
                 $publickey = openssl_pkey_get_details($resource);
                 $keypair['pub'] = $publickey['key'];
             } else {
                 throw new \Exception('Error in generateOpenSSLKeypair: Private key could not be determined from OpenSSL key resource.');
                 while ($msg = openssl_error_string()) {
                     throw new \Exception('Error in generateOpenSSLKeypair: OpenSSL reported error: ' . $msg);
                 }
                 return false;
             }
             openssl_pkey_free($resource);
             return $keypair;
         } else {
             throw new \Exception('Error in generateOpenSSLKeypair: OpenSSL PHP extension missing. Cannot continue.');
             return false;
         }
     } catch (Exception $e) {
         while ($msg = openssl_error_string()) {
             throw new \Exception('Error in generateOpenSSLKeypair: OpenSSL reported error: ' . $msg);
         }
         throw $e;
         return false;
     }
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:60,代码来源:OpenSSLExtension.php

示例14: parsePem

 /**
  * Returns a usable private and public key from a PEM encoded string.
  *
  * @param string $key  The private key.
  * @param string $pass The private key passphrase.
  *
  * @return array The private ([0]) and public ([1]) key.
  *
  * @throws InvalidArgumentException If a passphrase is required.
  * @throws RuntimeException         If the file could not be parsed.
  */
 public function parsePem($key, $pass = null)
 {
     $this->clearErrors();
     if (false === ($resource = openssl_pkey_get_private($key, $pass))) {
         $error = openssl_error_string();
         if (preg_match('/(bad password|bad decrypt)/', $error)) {
             throw new InvalidArgumentException('The private key passphrase is invalid.');
         }
         throw new RuntimeException("The private key could not be parsed: {$error}");
     }
     openssl_pkey_export($resource, $private);
     $details = openssl_pkey_get_details($resource);
     openssl_pkey_free($resource);
     return array($private, $details['key']);
 }
开发者ID:weierophinney,项目名称:box2,代码行数:26,代码来源:PrivateKeyHelper.php

示例15: onPasswordChange

 public function onPasswordChange(FormEvent $event)
 {
     // Get new password
     /** @var User $user */
     $user = $event->getForm()->getData();
     $password = $user->getPlainPassword();
     // Get pkey from session
     $privKey = $event->getRequest()->getSession()->get('pkey');
     // Secure pkey with new password
     $res = openssl_pkey_get_private($privKey);
     openssl_pkey_export($res, $privKey, $password);
     // Store pkey in user
     $user->setPrivateKey($privKey);
     unset($password);
     openssl_pkey_free($res);
     unset($privKey);
 }
开发者ID:timwhite,项目名称:TeamPasswordSafe,代码行数:17,代码来源:FOSListener.php


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