本文整理汇总了PHP中openssl_get_cipher_methods函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_get_cipher_methods函数的具体用法?PHP openssl_get_cipher_methods怎么用?PHP openssl_get_cipher_methods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_get_cipher_methods函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: __construct
public function __construct($config_array)
{
$expected_keys = array("cipher_method", "block_byte_size", "key_byte_size", "salt_byte_size", "mac_byte_size", "hash_function_name", "encryption_info_string", "authentication_info_string");
if (sort($expected_keys) !== true) {
throw Ex\CannotPerformOperationException("sort() failed.");
}
$actual_keys = array_keys($config_array);
if (sort($actual_keys) !== true) {
throw Ex\CannotPerformOperationException("sort() failed.");
}
if ($expected_keys !== $actual_keys) {
throw new Ex\CannotPerformOperationException("Trying to instantiate a bad configuration.");
}
$this->cipher_method = $config_array["cipher_method"];
$this->block_byte_size = $config_array["block_byte_size"];
$this->key_byte_size = $config_array["key_byte_size"];
$this->salt_byte_size = $config_array["salt_byte_size"];
$this->mac_byte_size = $config_array["mac_byte_size"];
$this->hash_function_name = $config_array["hash_function_name"];
$this->encryption_info_string = $config_array["encryption_info_string"];
$this->authentication_info_string = $config_array["authentication_info_string"];
Core::ensureFunctionExists('openssl_get_cipher_methods');
if (\in_array($this->cipher_method, \openssl_get_cipher_methods()) === false) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid OpenSSL cipher method.");
}
if (!\is_int($this->block_byte_size) || $this->block_byte_size <= 0) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid block byte size.");
}
if (!\is_int($this->key_byte_size) || $this->key_byte_size <= 0) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid key byte size.");
}
if ($this->salt_byte_size !== false) {
if (!is_int($this->salt_byte_size) || $this->salt_byte_size <= 0) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid salt byte size.");
}
}
if (!\is_int($this->mac_byte_size) || $this->mac_byte_size <= 0) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid MAC byte size.");
}
if (\in_array($this->hash_function_name, \hash_algos()) === false) {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid hash function name.");
}
if (!\is_string($this->encryption_info_string) || $this->encryption_info_string === "") {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid encryption info string.");
}
if (!\is_string($this->authentication_info_string) || $this->authentication_info_string === "") {
throw new Ex\CannotPerformOperationException("Configuration contains an invalid authentication info string.");
}
}
开发者ID:robstoll,项目名称:PuMa,代码行数:49,代码来源:Config.php
示例17: __construct
/**
* Cipher constructor.
* @param string $cipherMethod
* @throws CipherException
*/
public function __construct(string $cipherMethod = "aes-256-cbc")
{
// Check requirements
if (!extension_loaded("openssl") || !function_exists("hash")) {
throw CipherException::initError();
}
// Cipher Method
if (!in_array($cipherMethod, openssl_get_cipher_methods())) {
throw CipherException::badCipherMethod($cipherMethod);
}
// Bootstrap
$this->cipherMethod = $cipherMethod;
$this->defaultSecret = $this->validateKey(self::createKey("comely", 1), __METHOD__);
$this->defaultHashAlgo = $this->defaultHashAlgo("sha1");
$this->ivSize = openssl_cipher_iv_length($this->cipherMethod);
}
开发者ID:comelyio,项目名称:comely,代码行数:21,代码来源:Cipher.php
示例18: runtimeTest
/**
* Runs the runtime tests.
*
* @throws Ex\EnvironmentIsBrokenException
*/
public static function runtimeTest()
{
// 0: Tests haven't been run yet.
// 1: Tests have passed.
// 2: Tests are running right now.
// 3: Tests have failed.
static $test_state = 0;
if ($test_state === 1 || $test_state === 2) {
return;
}
if ($test_state === 3) {
/* If an intermittent problem caused a test to fail previously, we
* want that to be indicated to the user with every call to this
* library. This way, if the user first does something they really
* don't care about, and just ignores all exceptions, they won't get
* screwed when they then start to use the library for something
* they do care about. */
throw new Ex\EnvironmentIsBrokenException('Tests failed previously.');
}
try {
$test_state = 2;
Core::ensureFunctionExists('openssl_get_cipher_methods');
if (\in_array(Core::CIPHER_METHOD, \openssl_get_cipher_methods()) === false) {
throw new Ex\EnvironmentIsBrokenException('Cipher method not supported. This is normally caused by an outdated ' . 'version of OpenSSL (and/or OpenSSL compiled for FIPS compliance). ' . 'Please upgrade to a newer version of OpenSSL that supports ' . Core::CIPHER_METHOD . ' to use this library.');
}
RuntimeTests::AESTestVector();
RuntimeTests::HMACTestVector();
RuntimeTests::HKDFTestVector();
RuntimeTests::testEncryptDecrypt();
if (Core::ourStrlen(Key::createNewRandomKey()->getRawBytes()) != Core::KEY_BYTE_SIZE) {
throw new Ex\EnvironmentIsBrokenException();
}
if (Core::ENCRYPTION_INFO_STRING == Core::AUTHENTICATION_INFO_STRING) {
throw new Ex\EnvironmentIsBrokenException();
}
} catch (Ex\EnvironmentIsBrokenException $ex) {
// Do this, otherwise it will stay in the "tests are running" state.
$test_state = 3;
throw $ex;
}
// Change this to '0' make the tests always re-run (for benchmarking).
$test_state = 1;
}
开发者ID:defuse,项目名称:php-encryption,代码行数:48,代码来源:RuntimeTests.php
示例19: parseDekInfo
/**
* @param string $string
* @return array
*/
public function parseDekInfo($string)
{
$dek = explode(",", $string);
if (count($dek) !== 2) {
throw new \RuntimeException('Malformed DEK-Info');
}
$cipher = $dek[0];
$iv = $dek[1];
if (!in_array($cipher, openssl_get_cipher_methods())) {
throw new \RuntimeException('Unknown cipher method');
}
if (strlen($iv) / 2 !== openssl_cipher_iv_length($cipher)) {
throw new \RuntimeException('Bad IV length');
}
if (!ctype_xdigit($iv)) {
throw new \RuntimeException('Bad IV');
}
$iv = pack("H*", $iv);
return [$cipher, $iv];
}
开发者ID:afk11,项目名称:ecssh,代码行数:24,代码来源:EncryptedPrivateKeySerializer.php
示例20: decrypt
/**
* Decrypts a string encoded with mcrypt.<br />
* If mcrypt is not available, decrypts with xor
*
* @param string $text The text to decode
* @param string $key [optionnal] The key to use. Default is the application key
* @return string The decrypted string
*/
public static function decrypt($text, $key = null)
{
// Get the application key if no key is given
if ($key === null) {
$key = self::_getKey();
}
// Use openssl_decrypt with PHP >= 5.3.0
if (Config::get('general.crypt_method', 'openssl') === 'openssl' && function_exists('openssl_decrypt') && in_array('BF-ECB', openssl_get_cipher_methods())) {
$method = 'BF-ECB';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$msg = openssl_decrypt(strtr($text, '-_', '+/'), 'BF-ECB', $key);
} else {
if (function_exists('mcrypt_encrypt')) {
$size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($size, MCRYPT_RAND);
$text = base64_decode(str_pad(strtr($text, '-_', '+/'), strlen($text) % 4, '=', STR_PAD_RIGHT));
$msg = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv), "");
} else {
// ... else decrypt with xor technique
$n = mb_strlen($text, '8bit');
$m = mb_strlen($key, '8bit');
if ($n !== $m) {
$key = mb_substr(str_repeat($key, ceil($n / $m)), 0, $n, '8bit');
}
$msg = base64_decode($text) ^ $key;
}
}
// If zlib is active we uncompress the crypted value
if (function_exists('gzinflate')) {
$msg = @gzinflate($msg);
}
// To avoid truncated encoded strings
@(list($hash, $value) = explode('~~~', $msg));
if (self::check($value, $hash)) {
return $value;
}
return false;
}
开发者ID:salomalo,项目名称:php-oxygen,代码行数:46,代码来源:security.class.php
注:本文中的openssl_get_cipher_methods函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论