PHP implements enhanced mhash

*文
Release: 2023-03-18 14:50:01
Original
1393 people have browsed it

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)));
}
Copy after login


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

How to do PHP formhash

The above is the detailed content of PHP implements enhanced mhash. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!