How can I make the MD5 of php consistent with that of C? -Php Tutorial

Source: Internet
Author: User
The code for generating MD5 with c # is as follows: {code ...} the MD5 generated by the above code is f5da53705563c657581a6d0853286fdc. The problem is that the MD5 generated by c # is inconsistent with the MD5 generated by PHP. due to service restrictions, you cannot change the c # code. you can only start with PHP. The code for generating MD5 with c # is as follows:

Class CreateMD5 {static void Main (string [] args) {string source = ""; using (MD5 md5Hash = MD5.Create () {string hash = GetMd5Hash (md5Hash, source); Console. writeLine (hash) ;}} static string GetMd5Hash (MD5 md5Hash, string input) {// here it is Unicode byte [] data = md5Hash. computeHash (Encoding. unicode. getBytes (input); StringBuilder sBuilder = new StringBuilder (); for (int I = 0; I <data. length; I ++) {sBuilder. append (data [I]. toString ("x2");} return sBuilder. toString ();}}

The MD5 generated by the above code is f5da53705563c657581a6d0853286fdc.
The problem is that the MD5 generated by c # is inconsistent with the MD5 generated by PHP.

Due to business restrictions, you cannot change the c # code, but you can only start with PHP.

Reply content:

The code for generating MD5 with c # is as follows:

Class CreateMD5 {static void Main (string [] args) {string source = ""; using (MD5 md5Hash = MD5.Create () {string hash = GetMd5Hash (md5Hash, source); Console. writeLine (hash) ;}} static string GetMd5Hash (MD5 md5Hash, string input) {// here it is Unicode byte [] data = md5Hash. computeHash (Encoding. unicode. getBytes (input); StringBuilder sBuilder = new StringBuilder (); for (int I = 0; I <data. length; I ++) {sBuilder. append (data [I]. toString ("x2");} return sBuilder. toString ();}}

The MD5 generated by the above code is f5da53705563c657581a6d0853286fdc.
The problem is that the MD5 generated by c # is inconsistent with the MD5 generated by PHP.

Due to business restrictions, you cannot change the c # code, but you can only start with PHP.

Step 1 before md5

$ Tmp = mb_convert_encoding ('question Guide', 'utf-16le', 'utf8 ');

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.