mhash php,PHP Mhash 函数

这篇博客讨论了在PHP中使用mhash函数生成与DC客户端兼容的Tiger哈希的问题。作者提供了不同方法来实现Tiger哈希,包括修复Tiger算法的一个错误,并给出了如何根据mhash_count()获取可用哈希类型的示例。此外,还涉及到mhash函数在处理不同哈希方法时的注意事项,如SHA512。
摘要由CSDN通过智能技术生成

用户评论:

alexey dot kupershtokh at gmail dot com (2007-12-27 04:48:17)

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

ludicruz at yahoo dot com (2007-07-07 13:41:42)

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 (2006-12-06 00:44:10)

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

brentdothansenatgmaildotcom (2005-08-11 16:43:03)

Since it seems that the tiger hash bug has been labeled "bogus" here is a fix to give a correct result. I'm not a binary expert so if you come up with a better fix please let us know. Just do your MHASH_TIGER as normal then send the unaltered binary into tigerfix and you get a proper HEX return.

function tigerfix ($binary_hash) {

$my_split = str_split($binary_hash,8);

$my_tiger ="";

foreach($my_split as $key => $value) {

$my_split[$key] = strrev($value);

$my_tiger .= $my_split[$key];

}

$my_tiger_hex = bin2hex($my_tiger);

return $my_tiger_hex;

}

m1tk4 at hotmail dot com (2004-06-21 22:43:20)

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

(2001-07-31 19:13:47)

MHASH_HAVAL256 , MHASH_HAVAL192, etc...

refers to the HAVAL hash with 3 rounds.

To use HAVAL with 4 or 5 rounds, you have to

recompile the mhash library and either add

new hash names, or just change in mhash.c

the definitions of MHASH_HAVAL256,...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值