Enhanced mhash function implemented by PHP

Source: Internet
Author: User

Enhanced mhash function implemented by PHP

This article mainly introduces enhanced mhash functions implemented by PHP. When the default mhash function is used, an error is reported. Two solutions are available. For more information, see

When I use the php encryption function mhash today, the following error occurs: Fatal error: Call to undefined function mhash ()

Mhash is a built-in function of php, but an error is reported when it is used ..

The following two methods are summarized:

1. Import the php_mhash.dll extension file. In addition, you need to import libmhash. dll (the load dependency file of the mhash library ),

Load LoadFile C:/php/libmhash. dll in the Apache configuration file Httpd. conf ".

2. Use the 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 $ key and $ data parameters in the hmac_md5 function correspond to the original 3 and 2 parameters of mhash.

Both methods can smoothly use the mhash encryption function of php.

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.