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


PHP hash_algos函数代码示例

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


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

示例1: start

 static function start()
 {
     include_once __DIR__ . '/sessionDrivers/' . Settings::$sessionDriver . '.php';
     //self::$driver = new Settings::$sessionDriver();
     //session_set_save_handler(array(self::$driver, 'open'),array(self::$driver, 'close'),array(self::$driver, 'read'),
     //            array(self::$driver, 'write'),array(self::$driver, 'destroy'),array(self::$driver, 'gc'));
     register_shutdown_function('session_write_close');
     if (in_array(Settings::$session_hash, hash_algos())) {
         ini_set('session.hash_function', Settings::$session_hash);
     }
     ini_set('session.hash_bits_per_character', Settings::$hash_bits_per_character);
     $cookieParams = session_get_cookie_params();
     session_set_cookie_params(Settings::$sessionLifetime, $cookieParams["path"], $cookieParams["domain"], Settings::$secure, Settings::$httpOnly);
     session_name(Settings::$NAME);
     //буферизуем заголовок
     ob_start();
     //включаем CORS, если указано в настройках /*
     if (isset(Settings::$CORS) && Settings::$CORS && !empty($_SERVER['HTTP_ORIGIN'])) {
         header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
         header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
         header('Access-Control-Max-Age: 1000');
         header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
     }
     //включаем сессию
     session_start();
     ob_end_flush();
     //посылаем заголовок
 }
开发者ID:pdanver,项目名称:mir-ndv,代码行数:28,代码来源:Session.php

示例2: isAvailable

 public static function isAvailable()
 {
     if (!function_exists('hash_algos') || !function_exists('hash')) {
         return false;
     }
     return in_array(static::getHashName(), hash_algos(), true);
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:7,代码来源:Base.php

示例3: validateAlgorithm

 /**
  * Checks if the algorithm specified exists and throws an exception if it does not
  *
  * @param string $algorithm Name of the algorithm to validate
  *
  * @return bool
  * @throws InvalidArgumentException if the algorithm doesn't exist
  */
 public static function validateAlgorithm($algorithm)
 {
     if (!in_array($algorithm, hash_algos(), true)) {
         throw new InvalidArgumentException("The hashing algorithm specified ({$algorithm}) does not exist.");
     }
     return true;
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:15,代码来源:HashUtils.php

示例4: _detectHashSupport

 /**
  * @param string $algorithm
  * @throws Zend_Crypt_Exception
  */
 protected static function _detectHashSupport($algorithm)
 {
     if (function_exists('hash')) {
         self::$_type = self::TYPE_HASH;
         if (in_array($algorithm, hash_algos())) {
             return;
         }
     }
     if (function_exists('mhash')) {
         self::$_type = self::TYPE_MHASH;
         if (in_array($algorithm, self::$_supportedAlgosMhash)) {
             return;
         }
     }
     if (function_exists('openssl_digest')) {
         if ($algorithm == 'ripemd160') {
             $algorithm = 'rmd160';
         }
         self::$_type = self::TYPE_OPENSSL;
         if (in_array($algorithm, self::$_supportedAlgosOpenssl)) {
             return;
         }
     }
     /**
      * @see Zend_Crypt_Exception
      */
     require_once 'Zend/Crypt/Exception.php';
     throw new Zend_Crypt_Exception('\'' . $algorithm . '\' is not supported by any available extension or native function');
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:33,代码来源:Crypt.php

示例5: assertAlgorithmIsSupported

 private function assertAlgorithmIsSupported(string $algorithm)
 {
     $algorithms = hash_algos();
     if (in_array($algorithm, $algorithms, true) === false) {
         throw new InvalidArgumentException(sprintf('The algorithm "%s" is not supported on this system.', $algorithm));
     }
 }
开发者ID:hansott,项目名称:psr7-cookies,代码行数:7,代码来源:Hmac.php

示例6: pwValid

 /**
  * This function checks if a password is valid
  * @param $crypted  Password as appears in password file, optionally prepended with algorithm
  * @param $clear    Password to check
  */
 public static function pwValid($crypted, $clear)
 {
     assert('is_string($crypted)');
     assert('is_string($clear)');
     // Match algorithm string ('{SSHA256}', '{MD5}')
     if (preg_match('/^{(.*?)}(.*)$/', $crypted, $matches)) {
         // LDAP compatibility
         $algo = preg_replace('/^(S?SHA)$/', '${1}1', $matches[1]);
         $cryptedpw = $matches[2];
         if (in_array(strtolower($algo), hash_algos())) {
             // Unsalted hash
             return $crypted == self::pwHash($clear, $algo);
         }
         if ($algo[0] == 'S' && in_array(substr(strtolower($algo), 1), hash_algos())) {
             $php_algo = substr(strtolower($algo), 1);
             // Salted hash
             $hash_length = strlen(hash($php_algo, 'whatever', TRUE));
             $salt = substr(base64_decode($cryptedpw), $hash_length);
             return $crypted == self::pwHash($clear, $algo, $salt);
         }
         throw new Exception('Hashing algoritm \'' . strtolower($algo) . '\' not supported');
     } else {
         return $crypted === $clear;
     }
 }
开发者ID:shirlei,项目名称:simplesaml,代码行数:30,代码来源:Crypto.php

示例7: create_hash

 public function create_hash($string, $hash_method = 'sha1')
 {
     if (function_exists('hash') && in_array($hash_method, hash_algos())) {
         return hash($hash_method, $string);
     }
     return sha1($string);
 }
开发者ID:infobeans-arvind,项目名称:Cerberus,代码行数:7,代码来源:RegistrationController.php

示例8: pbkdf2

 private function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
 {
     $algorithm = strtolower($algorithm);
     if (!in_array($algorithm, hash_algos(), true)) {
         trigger_error('PBKDF2 ERROR: Invalid hash algorithm.', E_USER_ERROR);
     }
     if ($count <= 0 || $key_length <= 0) {
         trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR);
     }
     if (function_exists("hash_pbkdf2")) {
         if (!$raw_output) {
             $key_length = $key_length * 2;
         }
         return hash_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output);
     }
     $hash_length = strlen(hash($algorithm, "", true));
     $block_count = ceil($key_length / $hash_length);
     $output = "";
     for ($i = 1; $i <= $block_count; $i++) {
         $last = $salt . pack("N", $i);
         $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
         for ($j = 1; $j < $count; $j++) {
             $xorsum ^= $last = hash_hmac($algorithm, $last, $password, true);
         }
         $output .= $xorsum;
     }
     if ($raw_output) {
         return substr($output, 0, $key_length);
     } else {
         return bin2hex(substr($output, 0, $key_length));
     }
 }
开发者ID:ThesisThesis,项目名称:tbookAPI,代码行数:32,代码来源:Hasher.php

示例9: start_session

 function start_session($sessionName = 'PHPSESSID', $secure = false)
 {
     // Make sure the session cookie is not accessable via javascript.
     $httponly = true;
     // Hash algorithm to use for the sessionid. (use hash_algos() to get a list of available hashes.)
     $session_hash = 'sha512';
     // Check if hash is available
     if (in_array($session_hash, hash_algos())) {
         // Set the has function.
         ini_set('session.hash_function', $session_hash);
     }
     // 많은 해시의 문자 비트.
     // The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ",").
     ini_set('session.hash_bits_per_character', 5);
     // 쿠키 만이 아닌 URL 변수를 사용하여 세션을 강제로.
     ini_set('session.use_only_cookies', 1);
     // 세션 쿠키의 매개 변수를 가져옴
     $cookieParams = session_get_cookie_params();
     // 매개 변수를 설정합니다
     session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
     // 세션을 시작
     session_name($sessionName);
     // Now we cat start the session
     session_start();
     /**
      * TODO::
      * 이 줄은 세션을 다시 생성하고 기존 하나를 삭제합니다.
      * 또한 데이터베이스에 새로운 암호화 키를 생성한다.
      */
     // session_regenerate_id ( true );
 }
开发者ID:mclkim,项目名称:kaiser,代码行数:31,代码来源:DBSession.php

示例10: data

 public function data()
 {
     $tests = array();
     $knownAlgorithms = hash_algos();
     foreach (self::$data as $algorithm => $value) {
         // Some algorithms are not available in earlier versions of PHP so
         // theres no need to have tests for them.
         if (!in_array($algorithm, $knownAlgorithms)) {
             continue;
         }
         $raw = explode(',', $algorithm);
         $a = ucfirst($raw[0]);
         // passes
         $v = hash($algorithm, $value);
         $tests["{$algorithm} lower"] = array("isAValid{$a}", $v);
         $tests["{$algorithm} upper"] = array("isAValid{$a}", strtoupper($v));
         $tests["not {$algorithm} lower"] = array("isNotAValid{$a}", $v, "hash \"{$v}\" is not a valid {$raw['0']}");
         $tests["not {$algorithm} upper"] = array("isNotAValid{$a}", strtoupper($v), "hash \"" . strtoupper($v) . "\" is not a valid {$raw['0']}");
         // failures
         $tests["{$algorithm} too short"] = array("isAValid{$a}", '0', "hash \"0\" is a valid {$raw['0']}");
         $tests["{$algorithm} too long"] = array("isAValid{$a}", "0{$v}", "hash \"0{$v}\" is a valid {$raw['0']}");
         $tests["{$algorithm} bad character"] = array("isAValid{$a}", "z" . substr($v, 1), "hash \"z" . substr($v, 1) . "\" is a valid {$raw['0']}");
         $tests["not {$algorithm} too short"] = array("isNotAValid{$a}", '0');
         $tests["not {$algorithm} too long"] = array("isNotAValid{$a}", "0{$v}");
         $tests["not {$algorithm} bad character"] = array("isNotAValid{$a}", "z" . substr($v, 1));
     }
     return $tests;
 }
开发者ID:elliotchance,项目名称:concise,代码行数:28,代码来源:HashModuleTest.php

示例11: __construct

 public function __construct($config_array)
 {
     $expected_keys = array("key_byte_size", "checksum_hash_function", "checksum_byte_size");
     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 key configuration.");
     }
     $this->key_byte_size = $config_array["key_byte_size"];
     $this->checksum_hash_function = $config_array["checksum_hash_function"];
     $this->checksum_byte_size = $config_array["checksum_byte_size"];
     if (!\is_int($this->key_byte_size) || $this->key_byte_size <= 0) {
         throw new Ex\CannotPerformOperationException("Invalid key byte size.");
     }
     if (\in_array($this->checksum_hash_function, \hash_algos()) === false) {
         throw new Ex\CannotPerformOperationException("Invalid hash function name.");
     }
     if (!\is_int($this->checksum_byte_size) || $this->checksum_byte_size <= 0) {
         throw new Ex\CannotPerformOperationException("Invalid checksum byte size.");
     }
 }
开发者ID:robstoll,项目名称:PuMa,代码行数:26,代码来源:KeyConfig.php

示例12: do_hash

 /**
  * Hash encode a string
  *
  * @todo    Remove in version 3.1+.
  * @deprecated    3.0.0    Use PHP's native hash() instead.
  * @param    string $str
  * @param    string $type = 'sha1'
  * @return    string
  */
 function do_hash($str, $type = 'sha1')
 {
     if (!in_array(strtolower($type), hash_algos())) {
         $type = 'md5';
     }
     return hash($type, $str);
 }
开发者ID:at15,项目名称:codeignitordb,代码行数:16,代码来源:security_helper.php

示例13: getSupportedAlgorithms

 /**
  * Get the supported algorithm
  *
  * @return array
  */
 public static function getSupportedAlgorithms()
 {
     if (empty(self::$supportedAlgorithms)) {
         self::$supportedAlgorithms = hash_algos();
     }
     return self::$supportedAlgorithms;
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:12,代码来源:Hash.php

示例14: getConfigTreeBuilder

 /**
  * @return Symfony\Component\Config\Definition\Builder\TreeBuilder
  */
 public function getConfigTreeBuilder()
 {
     $treeBuilder = new TreeBuilder();
     $rootNode = $treeBuilder->root('coder');
     $rootNode->children()->scalarNode('secret_key')->isRequired()->cannotBeEmpty()->end()->integerNode('mac_length')->min(1)->defaultValue(6)->end()->integerNode('key_length')->min(1)->defaultValue(4)->end()->scalarNode('algo')->defaultValue('sha1')->validate()->ifNotInArray(hash_algos())->thenInvalid('Invalid algo "%s"')->end()->end();
     return $treeBuilder;
 }
开发者ID:sanchobbdo,项目名称:codes,代码行数:10,代码来源:CoderConfiguration.php

示例15: setAlgorithm

 /**
  * @param string $algorithm
  *
  * @return bool|void
  */
 public static function setAlgorithm($algorithm)
 {
     if (!in_array($algorithm, hash_algos())) {
         return false;
     }
     self::$algorithm = (string) $algorithm;
 }
开发者ID:rhurling,项目名称:nonces,代码行数:12,代码来源:Config.php


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