Home > Backend Development > PHP Tutorial > 如何使php的MD5与C#的MD5一致?

如何使php的MD5与C#的MD5一致?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:45:58
Original
2650 people have browsed it

有c#生成MD5的代码如下:

<code>   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 </code>
Copy after login
Copy after login

上述代码生成的MD5是 f5da53705563c657581a6d0853286fdc
现在问题是,c#生成的MD5 与 PHP 生成的MD5 不一致

由于业务限制,不能更改c#代码,只能从PHP下手。

回复内容:

有c#生成MD5的代码如下:

<code>   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 </code>
Copy after login
Copy after login

上述代码生成的MD5是 f5da53705563c657581a6d0853286fdc
现在问题是,c#生成的MD5 与 PHP 生成的MD5 不一致

由于业务限制,不能更改c#代码,只能从PHP下手。

md5前操作一步

<code>$tmp = mb_convert_encoding('提问指南', 'utf-16le', 'utf8');
</code>
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template