PHP MD5 16-bit and 32-bit implementation code

Source: Internet
Author: User

CopyCode The Code is as follows: <? PHP
Echo substr (MD5 ("admin"), 8, 16); // 16-bit MD5 Encryption
Echo "<HR> ";
Echo MD5 ("admin"); // 32-bit MD5 Encryption
?>

The 16-bit MD5 encryption is achieved by intercepting characters using the substr function ....

I don't want to study it in depth. I need to put my mental power in other key areas ~~

Today, I made a PHP link to the MSSQL database. The fields in the table in the database are encrypted using MD5 sixteen. However, MD5 in PHP is 32 bits by default, causing LogonProgramThere is no way to use MD5 encryption to match fields in the Table. Many people may be confused about this issue when searching on the Internet. After finding a solution, it is correct and recorded.

Use the substr function to intercept:

Substr (MD5 ("admin"), 8, 16); // 16-bit MD5 Encryption

MD5 ("admin"); // 32-bit MD5 Encryption

The results of the script home test are as follows:

We compare the results of several MD5 values in ASP.
Appendix: If you encounter an MD5 encrypted file and do not know the password, replace this set of encrypted data in the database.

Admin --- 16-bit encryption --- 7a57a5a743894a0e
Admin --- 32-bit encryption --- 21232f297a57a5a743894a0e4a801fc3
Admin --- 40-bit encryption --- 7a57a5a743894a0e4a801fc343894a0e4a801fc3

Substr (MD5 ("admin"), 8, 16); // The 16-bit MD5 encryption is the 16 characters starting from 8th characters. Therefore, you do not need to consider the uniqueness issue. It is correct. Some people on the Internet say that PhP5 supportsCopy codeThe Code is as follows: Echo MD5 ("admin", true); // return 16 bits, but this is only available in PhP5.

The output result is garbled. If you have any good code, share it.

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.