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


PHP openssl_get_cipher_methods函数代码示例

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


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

示例1: setCipher

 /**
  * @inheritdoc
  */
 public function setCipher($cipher)
 {
     if (!in_array($cipher, openssl_get_cipher_methods())) {
         throw new EncryptionException("Invalid cipher \"{$cipher}\"");
     }
     $this->cipher = $cipher;
 }
开发者ID:scaleddynamics,项目名称:Opulence,代码行数:10,代码来源:Encrypter.php

示例2: setEncryptionMode

 public function setEncryptionMode($mode = 'cbc', $strength = 128)
 {
     static $availableAlgorithms = null;
     static $defaultAlgo = 'aes-128-cbc';
     if (!is_array($availableAlgorithms)) {
         $availableAlgorithms = openssl_get_cipher_methods();
         foreach (array('aes-256-cbc', 'aes-256-ecb', 'aes-192-cbc', 'aes-192-ecb', 'aes-128-cbc', 'aes-128-ecb') as $algo) {
             if (in_array($algo, $availableAlgorithms)) {
                 $defaultAlgo = $algo;
                 break;
             }
         }
     }
     $strength = (int) $strength;
     $mode = strtolower($mode);
     if (!in_array($strength, array(128, 192, 256))) {
         $strength = 256;
     }
     if (!in_array($mode, array('cbc', 'ebc'))) {
         $mode = 'cbc';
     }
     $algo = 'aes-' . $strength . '-' . $mode;
     if (!in_array($algo, $availableAlgorithms)) {
         $algo = $defaultAlgo;
     }
     $this->method = $algo;
 }
开发者ID:joomla-projects,项目名称:media-manager-improvement,代码行数:27,代码来源:openssl.php

示例3: testSetAlgorithm

 public function testSetAlgorithm()
 {
     $algos = openssl_get_cipher_methods(true);
     $algo = $algos[array_rand($algos)];
     $this->crypt->setAlgorithm($algo);
     $this->assertEquals($algo, $this->crypt->getAlgorithm());
 }
开发者ID:ezimuel,项目名称:phpcrypto,代码行数:7,代码来源:SymmetricTest.php

示例4: testSupportedCiphersList

 public function testSupportedCiphersList()
 {
     $supported = $this->defaultCipher->getSupportedCiphers();
     $this->assertInternalType('array', $supported);
     $cipherMethods = openssl_get_cipher_methods();
     foreach ($supported as $method) {
         $this->assertTrue(in_array($method, $cipherMethods));
     }
 }
开发者ID:browomir,项目名称:open-encryption,代码行数:9,代码来源:CipherTest.php

示例5: __construct

 public function __construct(array $options = [])
 {
     if (!empty($options)) {
         $this->config = $options;
     }
     if (!\in_array($this->config['cipher'] . '-ctr', \openssl_get_cipher_methods())) {
         throw new Error('Cipher ' . $this->config['cipher'] . '-ctr' . ' not found!');
     }
 }
开发者ID:sagarjethi,项目名称:pco_prototype,代码行数:9,代码来源:OpenSSL.php

示例6: __construct

 /**
  * EncryptedPrivateKey constructor.
  * @param PrivateKeyInterface $key
  * @param string $method
  * @param string $iv
  */
 public function __construct(PrivateKeyInterface $key, $method, $iv)
 {
     $methods = openssl_get_cipher_methods();
     if (!in_array($method, array_values($methods))) {
         throw new \RuntimeException('Unknown cipher method');
     }
     $this->key = $key;
     $this->method = $method;
     $this->iv = $iv;
 }
开发者ID:afk11,项目名称:ecssh,代码行数:16,代码来源:EncryptedPrivateKey.php

示例7: encrypt

 /**
  * Encrypt the data
  *
  * @param string $data Data string to encrypt
  * @param string $key  Encryption key
  * @param string $mode Default mode (openssl or mcrypt)
  *
  * @return string Encrypted data string.
  */
 public function encrypt($data, $key, $mode = 'openssl')
 {
     if ($mode == 'openssl' && extension_loaded('openssl') && in_array('aes-256-cbc', openssl_get_cipher_methods())) {
         return $this->encryptOpenSsl($data, $key);
     }
     if ($mode != 'raw' && function_exists('mcrypt_create_iv') && mcrypt_get_cipher_name(MCRYPT_RIJNDAEL_128) !== false) {
         return $this->encryptMcrypt($data, $key);
     }
     throw new EncException('Either "openssl" PHP extension with "aes-256-cbc" cypher' . ' or "mcrypt" PHP extension with "MCRYPT_RIJNDAEL_128" cypher is required for AES encryption');
 }
开发者ID:tecnickcom,项目名称:tc-lib-pdf-encrypt,代码行数:19,代码来源:AESnopad.php

示例8: __construct

 public function __construct(string $cipher = null, string $hash = null, string $mode = null, bool $twoStep = false)
 {
     parent::__construct($cipher, $hash, $mode, $twoStep);
     $this->mCipher = $cipher ?? "AES-256";
     $this->mMode = $mode ?? "CBC";
     if (!function_exists("openssl_get_cipher_methods")) {
         throw new Exception("Could not find the OpenSSL module");
     } elseif (!in_array(strtoupper($this->mCipher . "-" . $this->mMode), openssl_get_cipher_methods())) {
         throw new Exception("The cipher '" . strtoupper($this->mCipher . "-" . $this->mMode) . "' is not supported by this platform installation");
     }
 }
开发者ID:IMPHP,项目名称:libimphp,代码行数:11,代码来源:Encrypter.php

示例9: getMethod

 /**
  * Select which method we will use for our crypto stuff
  *
  * @return string The selected method that is available
  */
 private function getMethod()
 {
     $availableMethods = openssl_get_cipher_methods();
     if (in_array('AES-256-CBC-HMAC-SHA256', $availableMethods)) {
         return 'AES-256-CBC-HMAC-SHA256';
     } elseif (in_array('AES-256-CBC', $availableMethods)) {
         return 'AES-256-CBC';
     }
     // just take the first one coming, it's better than nothing
     return $availableMethods[0];
 }
开发者ID:corcre,项目名称:elabftw,代码行数:16,代码来源:LegacyCrypto.php

示例10: __construct

 public function __construct($password, $method = null)
 {
     $this->_password = $password;
     if ($method) {
         $methods = openssl_get_cipher_methods(true);
         if (!in_array($method, $methods)) {
             throw new \LogicException('Unknown cipher algorithm');
         }
         $this->_method = $method;
     }
 }
开发者ID:boyxp,项目名称:bluefin-bak,代码行数:11,代码来源:openssl.php

示例11: __construct

 /**
  * EncryptedSubjectIdentifier constructor.
  *
  * @param string      $pairwise_encryption_key
  * @param string      $algorithm
  * @param null|string $iv
  * @param string      $salt
  */
 public function __construct($pairwise_encryption_key, $algorithm, $iv, $salt)
 {
     Assertion::nullOrString($iv);
     Assertion::string($salt);
     Assertion::string($pairwise_encryption_key);
     Assertion::string($algorithm);
     Assertion::inArray($algorithm, openssl_get_cipher_methods(), sprintf('The algorithm "%s" is not supported.', $algorithm));
     $this->pairwise_encryption_key = $pairwise_encryption_key;
     $this->algorithm = $algorithm;
     $this->salt = $salt;
     $this->iv = $iv;
 }
开发者ID:spomky-labs,项目名称:oauth2-server-library,代码行数:20,代码来源:EncryptedSubjectIdentifier.php

示例12: getSupportedAlgs

 public function getSupportedAlgs()
 {
     $ciphers = openssl_get_cipher_methods();
     $hashes = hash_algos();
     $results = array();
     foreach (self::$alg_params as $alg => $param) {
         if (in_array($param['cipher'], $ciphers) && in_array($param['hash'], $hashes)) {
             $results[] = $alg;
         }
     }
     return $results;
 }
开发者ID:kelvinmo,项目名称:simplejwt,代码行数:12,代码来源:AESCBC_HMACSHA2.php

示例13: _getCipherMethod

 /**
  * Get cipher method and verify that it's supported.
  *
  * @throws \RuntimeException
  * @return string
  */
 protected final function _getCipherMethod()
 {
     static $supported_ciphers;
     if (!isset($supported_ciphers)) {
         $supported_ciphers = array_flip(openssl_get_cipher_methods());
     }
     $method = $this->_cipherMethod();
     if (!isset($supported_ciphers[$method])) {
         throw new \RuntimeException("Cipher method {$method} is not" . " supported by this version of OpenSSL.");
     }
     return $method;
 }
开发者ID:sop,项目名称:jwx,代码行数:18,代码来源:AESCBCAlgorithm.php

示例14: setMethod

 private function setMethod()
 {
     // select the right method
     $this->availableMethods = openssl_get_cipher_methods();
     if (in_array('AES-256-CBC-HMAC-SHA256', $this->availableMethods)) {
         $this->method = 'AES-256-CBC-HMAC-SHA256';
     } elseif (in_array('AES-256-CBC', $this->availableMethods)) {
         $this->method = 'AES-256-CBC';
     } else {
         // just take the first one coming, I guess it's better than nothing.
         $this->method = $this->availableMethods[0];
     }
 }
开发者ID:jcapellman,项目名称:elabftw,代码行数:13,代码来源:Crypto.php

示例15: check_methods

 /**
  * checks if the encryption and hash methods are supported
  * @param $enc the encryption method.
  * @param $hash the hash method.
  * @throw Exception in case a method is not supported.
  */
 private static function check_methods($enc, $hash)
 {
     if (!function_exists('openssl_encrypt')) {
         throw new Exception('openssl_encrypt() not supported.');
     } else {
         if (!in_array($enc, openssl_get_cipher_methods())) {
             throw new Exception('Encryption method ' . $enc . ' not supported.');
         } else {
             if (!in_array(strtolower($hash), hash_algos())) {
                 throw new Exception('Hashing method ' . $hash . ' not supported.');
             }
         }
     }
 }
开发者ID:cls1991,项目名称:ryzomcore,代码行数:20,代码来源:mycrypt.php


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