Jump to content

Replace MHASH with HASH?


Guest

Recommended Posts

Our host has PHP 5 installed, and apparently it doesn't come with mhash, php is replacing with just 'hash'.

They say the function will be the same.

Is it safe to change the mhash function in authorize/transfer.inc.php from mhash to hash?

Thanks!

Link to comment
Share on other sites

I'm not seeing it as being a straight substitute. I took a look over at CubeCartForums.org and nothing relevant came up with mhash or anyone building newer versions of the gateways.

1) string mhash ( int $hash , string $data [, string $key ] )

2) string hash ( string $algo , string $data [, bool $raw_output ] )

3) string hash_hmac ( string $algo , string $data , string $key [, bool $raw_output ] )

There are minor differences between mhash() and hash_hmac(). So, maybe (not having tried it myself):

Line 125:

return (bin2hex (mhash(MHASH_MD5, $data, $key)));

to:

return (hash_hmac("md5", $data, $key)); 'outputs lower-case hex as default

I hope the CC powers-that-be decide to offer up a free upgrade for the gateways (and other code) that uses the obsoleted MHASH extension.

Link to comment
Share on other sites

It's not.... I put in the wrong code.

Here's the correct one:

Find the following:

	// compute HMAC-MD5

	// Uses PHP mhash extension. Pl sure to enable the extension

	function hmac ($key, $data)

	{

	return (bin2hex (mhash(MHASH_MD5, $data, $key)));

	}




and replace it with the following:


// compute HMAC-MD5

function hmac($passwd, $data)

{

	$algo = "md5";

	/* md5 and sha1 only */

	$algo=strtolower($algo);

	$p=array('md5'=>'H32','sha1'=>'H40');

	if(strlen($passwd)>64) $passwd=pack($p[$algo],$algo($passwd));

	if(strlen($passwd)<64) $passwd=str_pad($passwd,64,chr(0));



	$ipad=substr($passwd,0,64) ^ str_repeat(chr(0x36),64);

	$opad=substr($passwd,0,64) ^ str_repeat(chr(0x5C),64);



	return($algo($opad.pack($p[$algo],$algo($ipad.$data))));

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...