Last change
on this file since 14977 was
3282,
checked in by plg, 16 years ago
|
change: according to topic:15067, svn:keywords property was removed
|
-
Property svn:eol-style set to
LF
|
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.