Hash

Содержание

  • hash_algos — Возвращает список зарегистрированных алгоритмов хеширования
  • hash_copy — Копирует контекст хеширования
  • hash_equals — Timing attack safe string comparison
  • hash_file — Генерация хеш-значения, используя содержимое заданного файла
  • hash_final — Завершает инкрементальное хеширование и возвращает результат в виде хеш-кода
  • hash_hmac_file — Генерация хэш-кода на основе ключа, используя метод HMAC и содержимое полученного файла
  • hash_hmac — Генерация хеш-кода на основе ключа, используя метод HMAC
  • hash_init — Инициализация инкрементального контекста хеширования
  • hash_pbkdf2 — Generate a PBKDF2 key derivation of a supplied password
  • hash_update_file — Добавляет данные из файла в активный контекст хеширования
  • hash_update_stream — Добавляет данные из открытого потока в активный контекст хеширования
  • hash_update — Добавляет данные в активный контекст хеширования
  • hash — Генерирует хеш-код (дайджест сообщения)

Коментарии

Some tests with mhash and hash revealed on my machine that hash needs more than twice as long to create a hash than mhash. The average of one million cylces of Haval128, Haval256, Gost, CRC32, MD5, SHA1 and SHA256 was 450ms for mhash and 1150ms for hash.
2007-09-03 20:24:54
http://php5.kiev.ua/manual/ru/ref.hash.html
Автор:
For thoes of you who're looking to generate an NTLM hash (not an LM hash), I found out it's quite simple..

It uses the basic MD4 function, but the password needs to be in Unicode Little Endian encode first (this canbe achieved by the iconv function).

This can be done easily by using the following code:

<?php
function NTLMHash($Input) {
 
// Convert the password from UTF8 to UTF16 (little endian)
 
$Input=iconv('UTF-8','UTF-16LE',$Input);

 
// Encrypt it with the MD4 hash
 
$MD4Hash=bin2hex(mhash(MHASH_MD4,$Input));

 
// You could use this instead, but mhash works on PHP 4 and 5 or above
  // The hash function only works on 5 or above
  //$MD4Hash=hash('md4',$Input);

  // Make it uppercase, not necessary, but it's common to do so with NTLM hashes
 
$NTLMHash=strtoupper($MD4Hash);

 
// Return the result
 
return($NTLMHash);
}
?>

To produce an LM hash requires a fully-written script containing the algorithm used to make it.

Enjoy,
CraquePipe.
2008-03-24 18:42:41
http://php5.kiev.ua/manual/ru/ref.hash.html
And some code for LM hash:

<?php
function LMhash($string)
{
   
$string strtoupper(substr($string,0,14));

   
$p1 LMhash_DESencrypt(substr($string07));
   
$p2 LMhash_DESencrypt(substr($string77));

    return 
strtoupper($p1.$p2);
}

function 
LMhash_DESencrypt($string)
{
   
$key = array();
   
$tmp = array();
   
$len strlen($string);

    for (
$i=0$i<7; ++$i)
       
$tmp[] = $i $len ord($string[$i]) : 0;

   
$key[] = $tmp[0] & 254;
   
$key[] = ($tmp[0] << 7) | ($tmp[1] >> 1);
   
$key[] = ($tmp[1] << 6) | ($tmp[2] >> 2);
   
$key[] = ($tmp[2] << 5) | ($tmp[3] >> 3);
   
$key[] = ($tmp[3] << 4) | ($tmp[4] >> 4);
   
$key[] = ($tmp[4] << 3) | ($tmp[5] >> 5);
   
$key[] = ($tmp[5] << 2) | ($tmp[6] >> 6);
   
$key[] = $tmp[6] << 1;
   
   
$is mcrypt_get_iv_size(MCRYPT_DESMCRYPT_MODE_ECB);
   
$iv mcrypt_create_iv($isMCRYPT_RAND);
   
$key0 "";
   
    foreach (
$key as $k)
       
$key0 .= chr($k);
   
$crypt mcrypt_encrypt(MCRYPT_DES$key0"KGS!@#$%"MCRYPT_MODE_ECB$iv);

    return 
bin2hex($crypt);
}
?>

Some optimization?
2008-07-20 15:35:55
http://php5.kiev.ua/manual/ru/ref.hash.html
For Samba ueserPassword you can use:

(I am not very sure aboute the salt part, but it works for me like that)

<?php
function CRYPThash($string$salt null)
{
    if (!
$salt)
       
$salt rand(10,99);
   
    return 
"{CRYPT}".crypt($string$salt);
}
?>

In posted NTLMHash function you can also use:

<?php
// Encrypt it with the MD4 hash
$MD4Hash=hash('md4',$Input);
?>

So you don't need to install mhash libraries
2009-12-07 07:00:32
http://php5.kiev.ua/manual/ru/ref.hash.html
Note for FreeBSD with PHP-5. 

This is disabled by default; use the security/php5-hash port:
cd /usr/ports/security/php5-hash ; make install clean
(do not use the security/pecl-hash port as in the past, see the /usr/ports/UPDATING post from 20081211)
2010-01-11 09:22:45
http://php5.kiev.ua/manual/ru/ref.hash.html

    Поддержать сайт на родительском проекте КГБ