PHP Implementation Enhancements Mhash

Source: Internet
Author: User
How does PHP implement enhanced Mhash? This article mainly introduced the PHP implementation of the enhanced Mhash function, using the default Mhash function but error, found two solutions. We hope to help you.

Today, using PHP's cryptographic function Mhash, error: Fatal error:call to undefined function mhash ()

Mhash is a built-in function for PHP but uses an error.

Some studies summarize two methods:

1, Import php_mhash.dll extension file, in addition to import Libmhash.dll (Mhash library load dependent on this file),

Load LoadFile C:/php/libmhash.dll "in the Apache 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 =;    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 mhash original 3,2 parameters.

Both of these methods can be used successfully on the PHP mhash encryption function

Related recommendations:

PHP Encryption Extension Library-mhash extension Library instance Usage

How to install Mhash extension Library in PHP _php tutorial

PHP Formhash specifically how to do

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.