There is the code for C # generation MD5 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) { //这里是 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 now is that the MD5 generated by C # is inconsistent with the MD5 generated by PHP
Because of business constraints, you cannot change C # code, only from PHP.
Reply content:
There is the code for C # generation MD5 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) { //这里是 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 now is that the MD5 generated by C # is inconsistent with the MD5 generated by PHP
Because of business constraints, you cannot change C # code, only from PHP.
MD5 one step before the operation
$tmp = mb_convert_encoding('提问指南', 'utf-16le', 'utf8');