Last change
on this file since 2297 was
1912,
checked in by rub, 18 years ago
|
Update svn properties (svn:eol-style and svn:keywords)
|
-
Property svn:eol-style set to
LF
-
Property svn:keywords set to
Author Date Id Revision
|
File size:
637 bytes
|
Line | |
---|
1 | <?php |
---|
2 | //(hash) - enabled by default as of PHP 5.1.2 |
---|
3 | function hash_hmac($algo, $data, $key, $raw_output=false) |
---|
4 | { |
---|
5 | /* md5 and sha1 only */ |
---|
6 | $algo=strtolower($algo); |
---|
7 | $p=array('md5'=>'H32','sha1'=>'H40'); |
---|
8 | if ( !isset($p[$algo]) or !function_exists($algo) ) |
---|
9 | { |
---|
10 | $algo = 'md5'; |
---|
11 | } |
---|
12 | if(strlen($key)>64) $key=pack($p[$algo],$algo($key)); |
---|
13 | if(strlen($key)<64) $key=str_pad($key,64,chr(0)); |
---|
14 | |
---|
15 | $ipad=substr($key,0,64) ^ str_repeat(chr(0x36),64); |
---|
16 | $opad=substr($key,0,64) ^ str_repeat(chr(0x5C),64); |
---|
17 | |
---|
18 | $ret = $algo($opad.pack($p[$algo],$algo($ipad.$data))); |
---|
19 | if ($raw_output) |
---|
20 | { |
---|
21 | $ret = pack('H*', $ret); |
---|
22 | } |
---|
23 | return $ret; |
---|
24 | } |
---|
25 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.