本文整理汇总了PHP中mcrypt_get_iv_size函数的典型用法代码示例。如果您正苦于以下问题:PHP mcrypt_get_iv_size函数的具体用法?PHP mcrypt_get_iv_size怎么用?PHP mcrypt_get_iv_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mcrypt_get_iv_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decodePassword
public static function decodePassword($sPassword, $sSalt)
{
if (function_exists('mcrypt_encrypt') && function_exists('mcrypt_create_iv') && function_exists('mcrypt_get_iv_size') && defined('MCRYPT_RIJNDAEL_256') && defined('MCRYPT_MODE_ECB') && defined('MCRYPT_RAND')) {
return @base64_decode(trim(@mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($sSalt), base64_decode(trim($sPassword)), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
}
return @base64_decode(trim($sPassword));
}
示例2: __construct
/**
* Loads encryption configuration and validates the data.
*
* @param array|string custom configuration or config group name
* @throws Kohana_Exception
*/
public function __construct($config = FALSE)
{
if (!defined('MCRYPT_ENCRYPT')) {
throw new Kohana_Exception('encrypt.requires_mcrypt');
}
if (is_string($config)) {
$name = $config;
// Test the config group name
if (($config = Kohana::config('encryption.' . $config)) === NULL) {
throw new Kohana_Exception('encrypt.undefined_group', $name);
}
}
if (is_array($config)) {
// Append the default configuration options
$config += Kohana::config('encryption.default');
} else {
// Load the default group
$config = Kohana::config('encryption.default');
}
if (empty($config['key'])) {
throw new Kohana_Exception('encrypt.no_encryption_key');
}
// Find the max length of the key, based on cipher and mode
$size = mcrypt_get_key_size($config['cipher'], $config['mode']);
if (strlen($config['key']) > $size) {
// Shorten the key to the maximum size
$config['key'] = substr($config['key'], 0, $size);
}
// Find the initialization vector size
$config['iv_size'] = mcrypt_get_iv_size($config['cipher'], $config['mode']);
// Cache the config in the object
$this->config = $config;
Kohana::log('debug', 'Encrypt Library initialized');
}
示例3: __construct
public function __construct($_key = '', $_bit = 128, $_type = 'ecb', $_use_base64 = true)
{
// 加密字节
if (192 === $_bit) {
$this->_bit = MCRYPT_RIJNDAEL_192;
} elseif (128 === $_bit) {
$this->_bit = MCRYPT_RIJNDAEL_128;
} else {
$this->_bit = MCRYPT_RIJNDAEL_256;
}
// 加密方法
if ('cfb' === $_type) {
$this->_type = MCRYPT_MODE_CFB;
} elseif ('cbc' === $_type) {
$this->_type = MCRYPT_MODE_CBC;
} elseif ('nofb' === $_type) {
$this->_type = MCRYPT_MODE_NOFB;
} elseif ('ofb' === $_type) {
$this->_type = MCRYPT_MODE_OFB;
} elseif ('stream' === $_type) {
$this->_type = MCRYPT_MODE_STREAM;
} else {
$this->_type = MCRYPT_MODE_ECB;
}
// 密钥
if (!empty($_key)) {
$this->_key = $_key;
}
// 是否使用base64
$this->_use_base64 = $_use_base64;
$this->_iv_size = mcrypt_get_iv_size($this->_bit, $this->_type);
$this->_iv = mcrypt_create_iv($this->_iv_size, MCRYPT_RAND);
}
示例4: generateSettingsFile
/**
* Generate settings file
*/
public function generateSettingsFile($database_server, $database_login, $database_password, $database_name, $database_prefix, $database_engine)
{
// Check permissions for settings file
if (file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE)) {
$this->setError($this->language->l('%s file is not writable (check permissions)', self::SETTINGS_FILE));
return false;
} elseif (!file_exists(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE) && !is_writable(_PS_ROOT_DIR_ . '/' . dirname(self::SETTINGS_FILE))) {
$this->setError($this->language->l('%s folder is not writable (check permissions)', dirname(self::SETTINGS_FILE)));
return false;
}
// Generate settings content and write file
$settings_constants = array('_DB_SERVER_' => $database_server, '_DB_NAME_' => $database_name, '_DB_USER_' => $database_login, '_DB_PASSWD_' => $database_password, '_DB_PREFIX_' => $database_prefix, '_MYSQL_ENGINE_' => $database_engine, '_PS_CACHING_SYSTEM_' => 'CacheMemcache', '_PS_CACHE_ENABLED_' => '0', '_MEDIA_SERVER_1_' => '', '_MEDIA_SERVER_2_' => '', '_MEDIA_SERVER_3_' => '', '_COOKIE_KEY_' => Tools::passwdGen(56), '_COOKIE_IV_' => Tools::passwdGen(8), '_PS_CREATION_DATE_' => date('Y-m-d'), '_PS_VERSION_' => _PS_INSTALL_VERSION_);
// If mcrypt is activated, add Rijndael 128 configuration
if (function_exists('mcrypt_encrypt')) {
$settings_constants['_RIJNDAEL_KEY_'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
$settings_constants['_RIJNDAEL_IV_'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND));
}
$settings_content = "<?php\n";
foreach ($settings_constants as $constant => $value) {
$settings_content .= "define('{$constant}', '" . str_replace('\'', '\\\'', $value) . "');\n";
}
if (!file_put_contents(_PS_ROOT_DIR_ . '/' . self::SETTINGS_FILE, $settings_content)) {
$this->setError($this->language->l('Cannot write settings file'));
return false;
}
return true;
}
示例5: _decrypt
private static function _decrypt($value, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($value), MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
示例6: __construct
function __construct($cipher)
{
$this->cipher = $cipher;
$this->key_size = mcrypt_module_get_algo_key_size($cipher);
$this->block_size = mcrypt_module_get_algo_block_size($cipher);
$this->iv = str_repeat("", mcrypt_get_iv_size($cipher, 'ncfb'));
}
示例7: decrypted
public static function decrypted($encrypted, $key)
{
$data = base64_decode($encrypted);
$iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)), MCRYPT_MODE_CBC, $iv), "");
return $decrypted;
}
示例8: __construct
/**
* @param string $cypher
* @param string $mode
* @param int $ivMode
*/
public function __construct($cypher = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_ECB, $ivMode = MCRYPT_RAND)
{
$this->cypher = $cypher;
$this->mode = $mode;
$ivSize = mcrypt_get_iv_size($cypher, $mode);
$this->iv = mcrypt_create_iv($ivSize, $ivMode);
}
示例9: decrypt
/**
* 解密函数
* @param string $decrypt
* @param string $key
* @return string
*/
public function decrypt($decrypt, $key = '')
{
$decoded = base64_decode($decrypt);
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), $decoded, MCRYPT_MODE_ECB, $iv);
return $decrypted;
}
示例10: decrypt
/**
* see crypt::decrypt();
*/
public function decrypt($data)
{
if ($this->base64) {
$decoded = base64_decode($data);
} else {
$decoded = $data;
}
// extract values out of data
$iv_size = mcrypt_get_iv_size($this->cipher, $this->mode);
$iv = mb_substr($decoded, 0, $iv_size, 'latin1');
$hash_size = mb_strlen($this->hash(1), 'latin1');
$hash = mb_substr($decoded, $iv_size, $hash_size, 'latin1');
$cipher = mb_substr($decoded, $iv_size + $hash_size, mb_strlen($decoded, 'latin1'), 'latin1');
// comparing ciper with hash
if ($this->hash($cipher) != $hash) {
return false;
}
// decrypting
$decrypted = mcrypt_decrypt($this->cipher, $this->key, $cipher, $this->mode, $iv);
if ($decrypted !== false) {
return rtrim($decrypted, "");
} else {
return false;
}
}
示例11: __construct
public function __construct($key, $mode = MCRYPT_MODE_ECB, $iv = NULL, $bit = AESMcrypt::BIT_128)
{
// check mcrypt module
if (!extension_loaded("mcrypt")) {
trigger_error('AESMcrypt class need mcrypt module');
return;
}
switch ($bit) {
case AESMcrypt::BIT_192:
$this->_cipher = MCRYPT_RIJNDAEL_192;
break;
case AESMcrypt::BIT_256:
$this->_cipher = MCRYPT_RIJNDAEL_256;
break;
default:
$this->_cipher = MCRYPT_RIJNDAEL_128;
break;
}
$modes = array(MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB, MCRYPT_MODE_OFB, MCRYPT_MODE_NOFB);
if (in_array($mode, $modes)) {
$this->_mode = $mode;
} else {
$this->_mode = MCRYPT_MODE_ECB;
}
$this->_key = $key;
$this->_iv = $iv;
// check iv size, ecb模式不需要iv
if ($this->_mode != MCRYPT_MODE_ECB) {
$needIVSize = mcrypt_get_iv_size($this->_cipher, $this->_mode);
if (strlen($iv) != $needIVSize) {
trigger_error("IV size wrong, need a string of length {$needIVSize}");
return;
}
}
}
示例12: aesdecrypt
function aesdecrypt($s, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = substr($s, 0, $iv_size);
$crypto = substr($s, $iv_size);
return @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $crypto, MCRYPT_MODE_CBC, $iv);
}
示例13: decrypt
function decrypt($text, $salt)
{
if (!$text) {
return false;
}
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND)));
}
示例14: __construct
public function __construct($encryption_key)
{
$this->prefix = version_compare(PHP_VERSION, '5.3.7') < 0 ? '$2a' : '$2y';
$this->encryptionHash = str_split(hash('sha256', $encryption_key));
// SHA-256 hash array
$this->iv_size = mcrypt_get_iv_size($this->cipher, $this->mcryptMode);
}
示例15: do_encrypt
function do_encrypt($data)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypt = getEncryptionKey(32);
return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $encrypt, $data, MCRYPT_MODE_CBC, $iv));
}