Posted By

ezerick on 09/19/08


Tagged

php hash hmac digest


Versions (?)

md5 hash_hmac for php4


 / Published in: PHP
 

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

  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. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: aristoworks on January 27, 2010

this is a great tool.. I've been having some HMAC issues on a 5.0 installation and for certain reasons can't upgrade. I think this works for me.

You need to login to post a comment.