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

PHP hash_algos函数代码示例

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

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



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


示例16: __construct

 /**
  * @brief Constructor
  *
  * @param String $algo The algorithm
  */
 public function __construct($algo)
 {
     $algo = strtolower($algo);
     // Check for support
     if (extension_loaded('hash')) {
         // We got the hashing support, so let's check if the algorithm is
         // supported.
         if (arr::hasValue(hash_algos(), $algo)) {
             $this->module = self::MOD_HASH;
             $this->algo = $algo;
             return;
         }
     }
     if (extension_loaded('mhash')) {
         // No hash support but mhash support, can it handle the algorithm?
         $num = mhash_count();
         for ($i = 0; $i <= $num; $i++) {
             if (mhash_get_hash_name($i) == $algo) {
                 $this->module = self::MOD_MHASH;
                 $this->algo = $algo;
                 return;
             }
         }
     }
     // Fall back on legacy spport here, is the algorithm one of the
     // by php supported ones?
     if (arr::hasValue(array('md5', 'sha1', 'crc32'), $algo)) {
         $this->module = self::MOD_PHP;
         $this->algo = $algo;
         return;
     }
     // No support, throw exception
     throw new SecurityException("Request for unsupported hash algorithm");
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:39,代码来源:hash.php


示例17: setHashAlgorithm

 /**
  * @param string $hash_algorithm
  *
  * @throws \InvalidArgumentException
  */
 public function setHashAlgorithm($hash_algorithm)
 {
     if (!in_array($hash_algorithm, hash_algos())) {
         throw new \InvalidArgumentException(sprintf('Hash algorithm "%s" is not supported. Please use one of the algorithms listed by function "hash_algos".', $hash_algorithm));
     }
     $this->hash_algorithm = $hash_algorithm;
 }
开发者ID:spomky-labs,项目名称:php-http-digest,代码行数:12,代码来源:ServerHeaderGenerator.php


示例18: decode

 function decode($str)
 {
     $res = "";
     $length = (int) strlen($str);
     $res .= decode_line("md5", md5($str), "input");
     $res .= decode_line("sha1", sha1($str), "input");
     $res .= decode_line("base64 encode", base64_encode($str), "textarea");
     $res .= decode_line("base64 decode", base64_decode($str), "textarea");
     $res .= decode_line("hex to string", @pack("H*", $str), "textarea");
     $res .= decode_line("string to hex", bin2hex($str), "textarea");
     $ascii = "";
     for ($i = 0; $i < $length; $i++) {
         $ascii .= ord(substr($str, $i, 1)) . " ";
     }
     $res .= decode_line("ascii char", trim($ascii), "textarea");
     $res .= decode_line("reversed", strrev($str), "textarea");
     $res .= decode_line("lowercase", strtolower($str), "textarea");
     $res .= decode_line("uppercase", strtoupper($str), "textarea");
     $res .= decode_line("urlencode", urlencode($str), "textarea");
     $res .= decode_line("urldecode", urldecode($str), "textarea");
     $res .= decode_line("rawurlencode", rawurlencode($str), "textarea");
     $res .= decode_line("rawurldecode", rawurldecode($str), "textarea");
     $res .= decode_line("htmlentities", html_safe($str), "textarea");
     if (function_exists('hash_algos')) {
         $algos = hash_algos();
         foreach ($algos as $algo) {
             if ($algo == 'md5' || $algo == 'sha1') {
                 continue;
             }
             $res .= decode_line($algo, hash($algo, $str), "input");
         }
     }
     return $res;
 }
开发者ID:lionsoft,项目名称:b374k,代码行数:34,代码来源:convert.php


示例19: __construct

 /**
  * @param string $algorithm A PHP built-in hashing algorithm as defined by hash_algos()
  * @throws Exception
  */
 public function __construct($algorithm)
 {
     if (!in_array($algorithm, hash_algos())) {
         throw new Exception(sprintf('Hash algorithm "%s" not found in hash_algos()', $algorithm));
     }
     $this->algorithm = $algorithm;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:11,代码来源:PasswordEncryptor_PHPHash.php


示例20: setAlgorithm

	/**
	 * Choose an algorithm.
	 * @param string $algorithm
	 * @throws Void_Exception
	 */
	public function setAlgorithm($algorithm) {
		if (in_array($algorithm, hash_algos())) {
			$this->_algorithm = $algorithm;
		} else {
			throw new Void_Auth_Credential_Treatment_Exception(sprintf("Algorithm '%s' not supported by hash extension", $algorithm));
		}
	}
开发者ID:niieani,项目名称:nandu,代码行数:12,代码来源:Hmac.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP hash_call函数代码示例发布时间:2022-05-15
下一篇:
PHP hashToFile函数代码示例发布时间: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