• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mcrypt_get_key_size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了mcrypt_get_key_size函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))];
     }
 }
开发者ID:abenity,项目名称:abenity-php,代码行数:34,代码来源:ApiClient.php


示例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');
 }
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:40,代码来源:Encrypt.php


示例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;
         }
     }
 }
开发者ID:pagon,项目名称:framework,代码行数:41,代码来源:Cryptor.php


示例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');
 }
开发者ID:JasonWiki,项目名称:docs,代码行数:40,代码来源:Encrypt.php


示例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;
 }
开发者ID:toufikadfab,项目名称:PrestaShop-1.5,代码行数:30,代码来源:install.php


示例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;
 }
开发者ID:scalr,项目名称:scalr,代码行数:12,代码来源:Update20150116130622.php


示例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;
 }
开发者ID:spekkionu,项目名称:spekkionu-php-class-collection,代码行数:11,代码来源:Crypt.php


示例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();
 }
开发者ID:recipe,项目名称:scalr,代码行数:8,代码来源:GlobalVariables.php


示例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);
 }
开发者ID:patricknelson,项目名称:silverstripe-hybridsessions,代码行数:22,代码来源:HybridSessionStore.php


示例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));
 }
开发者ID:GamerSource,项目名称:Infected-CMS-2,代码行数:8,代码来源:aescrypter.php


示例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);
 }
开发者ID:d-knafo,项目名称:SafeCrypt,代码行数:9,代码来源:SafeCrypt.class.php


示例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);
 }
开发者ID:muhammetardayildiz,项目名称:framework,代码行数:18,代码来源:MCrypt.php


示例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;
 }
开发者ID:meixelsberger,项目名称:concrete5-5.7.0,代码行数:15,代码来源:EncryptionService.php


示例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();
 }
开发者ID:rickb838,项目名称:scalr,代码行数:15,代码来源:GlobalVariables.php


示例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));
 }
开发者ID:Lavoaster,项目名称:PVLive,代码行数:10,代码来源:Encryption.php


示例16: decode

 public static function decode($string)
 {
     $key = Config::item("application", "key");
     $key = mb_substr($key, 0, mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC));
     list($string, $ivCode) = explode("|", $string);
     $string = static::from64($string);
     $ivCode = static::from64($ivCode);
     $string = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string, MCRYPT_MODE_CBC, $ivCode);
     return rtrim($string, "");
 }
开发者ID:jura-php,项目名称:jura,代码行数:10,代码来源:Crypt.php


示例17: 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('SECURITY_TOKEN_ENCRYPTION'), 0, $len), $text, MCRYPT_MODE_ECB, $iv));
     }
     return $text;
 }
开发者ID:ojalehto,项目名称:concrete5-legacy,代码行数:15,代码来源:encryption.php


示例18: getKeySize

 /**
  * Returns the maximum key size that can be used with a particular
  * cipher type. Any key size equal to or less than the returned
  * value are legal key sizes.  Depending on if the local mycrypt
  * extension is linked against 2.2 or 2.3/2.4 the block mode could
  * be required, hence the if/else statement.
  *
  * @param  string $cipher_type
  * @return int
  */
 public function getKeySize($cipher_type = MCRYPT_TRIPLEDES)
 {
     $block_mode = 'cbc';
     $max_key_size = mcrypt_get_key_size($cipher_type);
     if ($max_key_size !== false) {
         return $max_key_size;
     } else {
         return mcrypt_get_key_size($cipher_type, $block_mode);
     }
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:20,代码来源:McryptExtension.php


示例19: random_aes_key

function random_aes_key($ksize)
{
    $chars = range(chr(0), chr(255));
    if ($ksize > mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB)) {
        echo 'Warning: ', __FUNCTION__, '() is intended for AES-128 key generation; key is too long.', PHP_EOL;
    }
    for ($key = '', $size = count($chars) - 1; strlen($key) < $ksize; $key .= $chars[rand(0, $size)]) {
    }
    return $key;
}
开发者ID:jjc224,项目名称:Matasano,代码行数:10,代码来源:16.php


示例20: 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(PASSWORD_SALT, 0, $len), $text, MCRYPT_MODE_ECB, $iv));
     }
     return $text;
 }
开发者ID:nveid,项目名称:concrete5,代码行数:15,代码来源:encryption.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mcrypt_list_algorithms函数代码示例发布时间:2022-05-15
下一篇:
PHP mcrypt_get_iv_size函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap