Skip to content

Instantly share code, notes, and snippets.

@docunext
Created October 10, 2010 23:28
Show Gist options
  • Select an option

  • Save docunext/619687 to your computer and use it in GitHub Desktop.

Select an option

Save docunext/619687 to your computer and use it in GitHub Desktop.
<?php
function hmac($key, $data, $hash = 'md5', $blocksize = 64) {
if (strlen($key)>$blocksize) {
$key = pack('H*', $hash($key));
}
$key = str_pad($key, $blocksize, chr(0));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
return $hash(($key^$opad) . pack('H*', $hash(($key^$ipad) . $data)));
}
echo hmac('hi', 'blah');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment