PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

hash_algos> <HaruPage::textRect
Last updated: Mon, 26 Nov 2007

view this page in

hash Functions

简介

Message Digest (hash) engine. Allows direct or incremental processing of arbitrary length messages using a variety of hashing algorithms.

需求

The Hash extension requires no external libraries and is enabled by default as of PHP 5.1.2. It may be explicitly disabled by using the --disable-hash switch to configure. Earlier versions of PHP may incorporate the Hash extension by installing the » PECL module.

资源类型

This extension defines a Hashing Context resource returned by hash_init().

预定义常量

以下常量由本扩展模块定义,因此只有在本扩展模块被编译到 PHP 中,或者在运行时被动态加载后才有效。

HASH_HMAC (integer)
Optional flag for hash_init(). Indicates that the HMAC digest-keying algorithm should be applied to the current hashing context.

Table of Contents

  • hash_algos — Return a list of registered hashing algorithms
  • hash_file — Generate a hash value using the contents of a given file
  • hash_final — Finalize an incremental hash and return resulting digest
  • hash_hmac_file — Generate a keyed hash value using the HMAC method and the contents of a given file
  • hash_hmac — Generate a keyed hash value using the HMAC method
  • hash_init — Initialize an incremental hashing context
  • hash_update_file — Pump data into an active hashing context from a file
  • hash_update_stream — Pump data into an active hashing context from an open stream
  • hash_update — Pump data into an active hashing context
  • hash — Generate a hash value (message digest)


hash_algos> <HaruPage::textRect
Last updated: Mon, 26 Nov 2007
 
add a note add a note User Contributed Notes
hash
CraquePipe
25-Mar-2008 08:42
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.
rbemrose at vgmusic dot com
17-Oct-2007 09:55
martin:  That's because some distributions, such as FreeBSD's ports and Debian's apt split PHP's modules into different packages.
martin
28-Sep-2007 03:28
I tried to use Hash() function on my PHP 5.2.3 (FreeBSD 6.2) but there was no Hash() function. (it should be available by default from version 5.1.2)

Hash() function was working after installing "security/pecl-hash" port.
nb_removethis_ at wtal dot de
04-Sep-2007 08:24
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.

hash_algos> <HaruPage::textRect
Last updated: Mon, 26 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites