Home > Backend Development > PHP Tutorial > Enhanced mhash function implemented in PHP, mhash function implemented in php_PHP tutorial

Enhanced mhash function implemented in PHP, mhash function implemented in php_PHP tutorial

WBOY
Release: 2016-07-13 09:52:26
Original
801 people have browsed it

Enhanced mhash function implemented in PHP, mhash function implemented in PHP

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1008015.htmlTechArticle Enhanced mhash function implemented by PHP, PHP implements mhash function. When using PHP’s encryption function mhash today, an error is reported: Fatal error: Call to undefined function mhash() mhash is a built-in part of php...
Related labels:
php
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