The enhanced Mhash function for PHP implementations
This article mainly introduced the PHP implementation of the enhanced Mhash function, using the default Mhash function times wrong, found two solutions, the need for friends can refer to the following
Today, using PHP's cryptographic function Mhash, error: Fatal error:call to undefined function mhash ()
Mhash is a built-in function for PHP but uses an error.
Some studies summarize two methods:
1, Import php_mhash.dll extension file, in addition to import Libmhash.dll (Mhash library load dependent on this file),
Load LoadFile C:/php/libmhash.dll "in the Apache configuration file httpd.conf.
2, use the custom Mhash enhancement function.
The code is as follows:
function Hmac_md5 ($key, $data)
{
if (extension_loaded (' Mhash '))
{
Return Bin2Hex (Mhash (MHASH_MD5, $data, $key));
}
$b = 64;
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)));
}
The parameters $key and $data in the HMAC_MD5 function correspond to mhash original 3,2 parameters.
Both of these methods can be used successfully on the PHP mhash encryption function
http://www.bkjia.com/PHPjc/1007658.html www.bkjia.com true http://www.bkjia.com/PHPjc/1007658.html techarticle PHP Implementation of the enhanced Mhash function This article mainly introduces the implementation of the PHP enhanced Mhash function, using the default Mhash function times wrong, found two solutions, the need for friends can refer to the following ...