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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:45:582638browse

有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>

上述代码生成的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>

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

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

md5前操作一步

<code>$tmp = mb_convert_encoding('提问指南', 'utf-16le', 'utf8');
</code>
Statement:
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