md5 hash_hmac for php4


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function hmac ($key, $data)
  2. {
  3. // RFC 2104 HMAC implementation for php.
  4. // Creates an md5 HMAC.
  5. // Eliminates the need to install mhash to compute a HMAC
  6. // Hacked by Lance Rushing
  7.  
  8. $b = 64; // byte length for md5
  9. if (strlen($key) > $b) {
  10. $key = pack("H*",md5($key));
  11. }
  12. $key = str_pad($key, $b, chr(0x00));
  13. $ipad = str_pad('', $b, chr(0x36));
  14. $opad = str_pad('', $b, chr(0x5c));
  15. $k_ipad = $key ^ $ipad ;
  16. $k_opad = $key ^ $opad;
  17.  
  18. return md5($k_opad . pack("H*",md5($k_ipad . $data)));
  19. }

URL: http://www.php.net/manual/en/function.mhash.php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.