Mhash 函数
目录
- mhash_count — Gets the highest available hash ID
- mhash_get_block_size — Gets the block size of the specified hash
- mhash_get_hash_name — Gets the name of the specified hash
- mhash_keygen_s2k — Generates a key
- mhash — Computes hash

User Contributed Notes 4 notes
m1tk4 at hotmail dot com ¶
18 years ago
To enable mhash on RHEL/Fedora Core/other RPM-based Linuxes without rebuilding PHP, get the php-mhash and mhash RPMs at http://phprpms.sourceforge.net/mhash
ludicruz at yahoo dot com ¶
14 years ago
to robert at mediamonks dot com
This will work better, in your function you can just use the constant function to pull in the actual value of MHASH_SHA512 or whatever.
function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash(constant($strHashMethod), $argStrString));
return $strHashedString;
}
now:
echo getHashNotWorking('SHA512', 'some string');
works how you want it.
robert at mediamonks dot com ¶
15 years ago
function getHashNotWorking($argStrHashMethod, $argStrString)
{
$strHashMethod = 'MHASH_' . $argStrHashMethod;
$strHashedString = bin2hex(mhash($strHashMethod, $argStrString));
return $strHashedString;
}
echo getHashNotWorking('SHA512', 'some string');
This will return an error about the mhash function expecting a long type instead of a string.
=============================
for ($intI = 0; $intI <= mhash_count(); $intI++)
{
$arrHashTypes[mhash_get_hash_name($intI)] = $intI;
}
function getHashWorking($argStrType, $argStrString)
{
global $arrHashTypes;
$strHashedString = bin2hex(mhash($arrHashTypes[$argStrType], $argStrString));
return $strHashedString;
}
echo getHashWorking('SHA512', 'some string');
This will return the hash with the desired hash method
alexey dot kupershtokh at gmail dot com ¶
14 years ago
There's a class for generating TTH compatible with DC clients (DC++, StrongDC, ...) which uses mhash() with tiger algorithm:
http://kupershtokh.blogspot.com/2007/12/on-phpclub.html