本文整理汇总了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();
//посылаем заголовок
}
示例2: isAvailable
public static function isAvailable()
{
if (!function_exists('hash_algos') || !function_exists('hash')) {
return false;
}
return in_array(static::getHashName(), hash_algos(), true);
}
示例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;
}
示例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');
}
示例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));
}
}
示例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;
}
}
示例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);
}
示例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));
}
}
示例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 );
}
示例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;
}
示例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.");
}
}
示例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);
}
示例13: getSupportedAlgorithms
/**
* Get the supported algorithm
*
* @return array
*/
public static function getSupportedAlgorithms()
{
if (empty(self::$supportedAlgorithms)) {
self::$supportedAlgorithms = hash_algos();
}
return self::$supportedAlgorithms;
}
示例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;
}
示例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;
}