作者knockout (触不到的恋人(b))
看板PHP
标题Re: [徵求] PHP5 > function mhash()
时间Thu Jul 12 10:18:14 2007
※ 引述《tirme (Tirme)》之铭言:
: 我在网路上看有人说PHP5不支援mhash
: 我使用PHP5.2.1版(appserv2.5.7 win32)
: 解开php.ini的extension=php_mhash.dll 并且restart了
: 但是仍然无法找到function mhash()
: 请问有办法解决吗?
: 感谢帮忙
php官方就有人有写好的函式可以用了 ~~
function hmac ($key, $data)
{
// RFC 2104 HMAC implementation for php.
// Creates an md5 HMAC.
// Eliminates the need to install mhash to compute a HMAC
// Hacked by Lance Rushing
$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*",md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad ;
$k_opad = $key ^ $opad;
return md5($k_opad . pack("H*",md5($k_ipad . $data)));
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.132.101.76