本文整理汇总了PHP中mcrypt_get_key_size函数的典型用法代码示例。如果您正苦于以下问题:PHP mcrypt_get_key_size函数的具体用法?PHP mcrypt_get_key_size怎么用?PHP mcrypt_get_key_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mcrypt_get_key_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* ApiClient constructor
* @param String $api_username Your API Username
* @param String $api_password Your API Password
* @param String $api_key Your API Key
* @param Integer $version The API version
* @param Integer $timeout Set how long to wait for the API to respond
* @return null
*/
public function __construct($api_username, $api_password, $api_key, $version = 1, $timeout = 10)
{
// Set API Credentials
$this->api_username = $api_username;
$this->api_password = $api_password;
$this->api_key = $api_key;
$this->public_key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC8NVUZUtr2IHiFoY8s/qFGmZOIewAvg' . 'S4FMXWZ81Qc8lkAlZr9e171xn4PgKr+S7YsfCt+1XKyo5XmrJyaNUe/aRptB93NFn6RoFzExgfpkooxcHpWcP' . 'y+Hb5e0rwPDBA6zfyrYRj8uK/1HleFEr4v8u/HbnJmiFoNJ2hfZXn6Qw== phpseclib-generated-key';
// Set API Version
$this->version = 1;
if (is_numeric($version) && $version > 0 && $version < 2) {
$this->version = $version;
}
// Set API Timeout
$this->timeout = 10;
if (is_numeric($version)) {
$this->timeout = $timeout;
}
// Define a code alphabet for generating strings
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
// Create Triple DES Key
$triple_des_size = mcrypt_get_key_size('tripledes', 'cbc');
for ($i = 0; $i < $triple_des_size; $i++) {
$this->triple_des_key .= $codeAlphabet[$this->cryptoRandSecure(0, strlen($codeAlphabet))];
}
}
示例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
/**
* @param array|string $options
* @throws \InvalidArgumentException
*
* new Cryptor('key')
* new Cryptor(array('key' => 'test', 'cipher' => MCRYPT_RIJNDAEL_192))
*/
public function __construct($options = array())
{
if ($options) {
if (is_array($options)) {
$this->options = $options + $this->options;
} else {
$this->options['key'] = (string) $options;
}
}
if (!$this->options['key']) {
throw new \InvalidArgumentException('Cryptor need key param');
}
// Find the max length of the key, based on cipher and mode
$size = mcrypt_get_key_size($this->options['cipher'], $this->options['mode']);
if (isset($this->options['key'][$size])) {
// Shorten the key to the maximum size
$this->options['key'] = substr($this->options['key'], 0, $size);
}
// Store the IV size
$this->_iv_size = mcrypt_get_iv_size($this->options['cipher'], $this->options['mode']);
// Set the rand type if it has not already been set
if ($this->options['rand'] === null) {
if (defined('MCRYPT_DEV_URANDOM')) {
// Use /dev/urandom
$this->options['rand'] = MCRYPT_DEV_URANDOM;
} elseif (defined('MCRYPT_DEV_RANDOM')) {
// Use /dev/random
$this->options['rand'] = MCRYPT_DEV_RANDOM;
} else {
// Use the system random number generator
$this->options['rand'] = MCRYPT_RAND;
}
}
}
示例4: __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('To use the Encrypt library, mcrypt must be enabled in your PHP installation');
}
if (is_string($config)) {
$name = $config;
// Test the config group name
if (($config = Kohana::config('encryption.' . $config)) === NULL) {
throw new Kohana_Exception('The :name: group is not defined in your configuration.', array(':name:' => $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('To use the Encrypt library, you must set an encryption key in your config file');
}
// 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::add('debug', 'Encrypt Library initialized');
}
示例5: 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;
}
示例6: __construct
/**
* UpdateCrypto
*
* {@inheritdoc}
*/
public function __construct(SplFileInfo $fileInfo, ArrayObject $collection)
{
parent::__construct($fileInfo, $collection);
$this->source = \Scalr::getContainer()->crypto(MCRYPT_TRIPLEDES, MCRYPT_MODE_CFB, null, 24, 8);
$this->globals = \Scalr::getContainer()->crypto(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB, null, mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB), mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB));
$this->target = \Scalr::getContainer()->crypto;
}
示例7: _getKey
/**
* Returns the correct size key for the algorithm
* @return string
*/
private function _getKey()
{
$key_size = mcrypt_get_key_size($this->_algorithm, MCRYPT_MODE_ECB);
$key = str_pad($this->_key, $key_size, '0');
$key = substr($key, 0, $key_size);
return $key;
}
示例8: __construct
public function __construct($envId, $scope = Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT)
{
$this->crypto = new Scalr_Util_CryptoTool(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB, @mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB), @mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB));
$this->cryptoKey = @file_get_contents(APPPATH . "/etc/.cryptokey");
$this->envId = $envId;
$this->scope = $scope;
$this->db = \Scalr::getDb();
}
示例9: __construct
/**
* @param $key a per-site secret string which is used as the base encryption key.
* @param $salt a per-session random string which is used as a salt to generate a per-session key
*
* The base encryption key needs to stay secret. If an attacker ever gets it, they can read their session,
* and even modify & re-sign it.
*
* The salt is a random per-session string that is used with the base encryption key to create a per-session key.
* This (amongst other things) makes sure an attacker can't use a known-plaintext attack to guess the key.
*
* Normally we could create a salt on encryption, send it to the client as part of the session (it doesn't
* need to remain secret), then use the returned salt to decrypt. But we already have the Session ID which makes
* a great salt, so no need to generate & handle another one.
*/
public function __construct($key, $salt)
{
$this->ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$this->keySize = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
$this->key = $key;
$this->salt = $salt;
$this->saltedkey = function_exists('hash_pbkdf2') ? hash_pbkdf2('sha256', $this->key, $this->salt, 1000, $this->keySize, true) : $this->hash_pbkdf2('sha256', $this->key, $this->salt, 100, $this->keySize);
}
示例10: __construct
public function __construct($key, $algo = 0)
{
if (!isset(self::$algos[$algo])) {
throw new Exception('AESCrypter::__construct: algorithem ID not available!', 404);
}
$this->algo =& self::$algos[$algo];
$this->key = substr($key, 0, mcrypt_get_key_size($this->algo, MCRYPT_MODE_ECB));
}
示例11: decrypt
public static function decrypt($data)
{
$keyHash = md5(self::$key);
$key = substr($keyHash, 0, mcrypt_get_key_size(self::$cipher, self::$mode));
$iv = substr($keyHash, 0, mcrypt_get_block_size(self::$cipher, self::$mode));
$data = base64_decode($data);
$data = mcrypt_decrypt(self::$cipher, $key, $data, self::$mode, $iv);
return rtrim($data);
}
示例12: __construct
/**
* Constructor.
*
* @access public
* @param string $key Encryption key
* @param \mako\security\crypto\padders\PadderInterface $padder Padder instance
* @param int $cipher Cipher
* @param int $mode Mode
*/
public function __construct($key, PadderInterface $padder, $cipher = null, $mode = null)
{
$this->key = $key;
$this->padder = $padder;
$this->cipher = $cipher ?: MCRYPT_RIJNDAEL_256;
$this->mode = $mode ?: MCRYPT_MODE_CBC;
$this->keySize = mcrypt_get_key_size($this->cipher, $this->mode);
$this->ivSize = mcrypt_get_iv_size($this->cipher, $this->mode);
}
示例13: encrypt
/**
* Takes un-encrypted text and encrypts it.
* @param string $text
* @return string $text
*/
public static function encrypt($text)
{
if (function_exists('mcrypt_encrypt')) {
$iv_size = mcrypt_get_iv_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$len = mcrypt_get_key_size(MCRYPT_XTEA, MCRYPT_MODE_ECB);
$text = base64_encode(mcrypt_encrypt(MCRYPT_XTEA, substr(Config::get('concrete.security.token.encryption'), 0, $len), $text, MCRYPT_MODE_ECB, $iv));
}
return $text;
}
示例14: __construct
/**
* @param int $accountId
* @param int $envId
* @param string $scope
*/
public function __construct($accountId = 0, $envId = 0, $scope = Scalr_Scripting_GlobalVariables::SCOPE_SCALR)
{
$this->crypto = new Scalr_Util_CryptoTool(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB, @mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB), @mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB));
$this->cryptoKey = @file_get_contents(APPPATH . "/etc/.cryptokey");
$this->accountId = $accountId;
$this->envId = $envId;
$this->scope = $scope;
$this->listScopes = [self::SCOPE_SCALR, self::SCOPE_ACCOUNT, self::SCOPE_ENVIRONMENT, self::SCOPE_ROLE, self::SCOPE_FARM, self::SCOPE_FARMROLE, self::SCOPE_SERVER];
$this->db = \Scalr::getDb();
}
示例15: decrypt
public static function decrypt($string)
{
// Unpackage the encoded, encrypted string.
list($encoded_string, $encoded_iv) = explode('|', $string);
$encrypted_string = base64_decode($encoded_string);
$iv = base64_decode($encoded_iv);
// Trim encryption key to size supported by this cipher.
$key = substr(DF_ENCRYPTION_KEY, 0, mcrypt_get_key_size(DF_ENCRYPTION_CIPHER, MCRYPT_MODE_ECB));
return trim(mcrypt_decrypt(DF_ENCRYPTION_CIPHER, $key, $encrypted_string, MCRYPT_MODE_ECB, $iv));
}