Enhanced mhash function implemented in PHP_PHP tutorial

WBOY
Release: 2016-07-13 09:52:31
Original
1067 people have browsed it

Enhanced mhash function implemented in PHP

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. Friends in need can refer to it

When I used PHP’s encryption function mhash today, I got an error: 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.

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/1007658.htmlTechArticleEnhanced mhash function implemented in PHP This article mainly introduces the enhanced mhash function implemented in PHP, using the default mhash The function reported an error, and I found two solutions. Friends who need it can refer to it...
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