How do I implement HMAC-MD5 in PHP4?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello, I'm using PHP 4.  I'm trying to build a form to send payment
information to Authorize.Net.  In the documentation for their "Simple
Integration Method 1.0" they say I need to generate a fingerprint using
logic like:

FingerPrint =

Does anyone know what the HMAC-MD5 equivalent function is in PHP?

Thanks for your help, - Dave

Re: How do I implement HMAC-MD5 in PHP4?

this is code from osCommerce - an opensource project on sourceforge
(look at its license before using)

// compute HMAC-MD5
// Uses PHP mhash extension. Pl sure to enable the extension
// function hmac ($key, $data) {
//   return (bin2hex (mhash(MHASH_MD5, $data, $key)));

// Thanks is lance from
//lance_rushing at hot* spamfree *mail dot com
//27-Nov-2002 09:36
//Want to Create a md5 HMAC, but don't have hmash installed?
//Use this:

function hmac ($key, $data)
   // RFC 2104 HMAC implementation for php.
   // Creates an md5 HMAC.
   // Eliminates the need to install mhash to compute a HMAC
   // Hacked by Lance Rushing

   $b = 64; // byte length for md5
   if (strlen($key) > $b) {
       $key = pack("H*",md5($key));
   $key  = str_pad($key, $b, chr(0x00));
   $ipad = str_pad('', $b, chr(0x36));
   $opad = str_pad('', $b, chr(0x5c));
   $k_ipad = $key ^ $ipad ;
   $k_opad = $key ^ $opad;

   return md5($k_opad  . pack("H*",md5($k_ipad . $data)));
// end code from lance (resume code)

Site Timeline