When I used PHP’s encryption function mhash today, an error was reported: Fatal error: Call to undefined function mhash()
mhash is a built-in function of php but an error is reported when using it..
After some research, we summarized two methods:
1. Import the php_mhash.dll extension file. In addition, import libmhash.dll (the loading of the mhash library depends on this file),
Load LoadFile C:/php/libmhash.dll” in Apache’s configuration file Httpd.conf.
2. Use custom mhash enhancement function.
Copy code 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 the original 3,2 parameters of mhash.
Both of these methods can be used smoothly using PHP’s mhash encryption function