Home >Backend Development >PHP Tutorial >PHP implements enhanced mhash
How does PHP implement enhanced mhash? This article mainly introduces the enhanced mhash function implemented in PHP. When using the default mhash function, an error is reported, and two solutions are found. I hope to be helpful.
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 was reported when using it..
Some research summarizes 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 the custom mhash enhancement function.
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))); }
hmac_md5 The parameters $key and $data in the function correspond to the original 3,2 parameters of mhash.
Both of these methods can be used successfully with PHP's mhash encryption function
Related Recommended:
PHP encryption extension library-Mhash extension library example usage detailed explanation
How to install in PHP Mhash extension library_PHP tutorial
The above is the detailed content of PHP implements enhanced mhash. For more information, please follow other related articles on the PHP Chinese website!