PHP 和 C# 中不同的 MD5 哈希值

如果我更改输入字符串,为什么哈希值会不同?


我的 C# 代码是:


public static string CreateMD5(string strInput)

    {

        using (MD5 md5 = MD5.Create())

        {

            byte[] inputBytes = Encoding.UTF8.GetBytes(strInput);

            byte[] hashBytes = md5.ComputeHash(inputBytes);


            string hashedString = BitConverter.ToString(hashBytes).Replace("-", "").ToLower();

            return hashedString;

        }

    }

在 PHP 中,我使用该md5()函数。这是一项在线服务,所以我没有源代码;我只是使用该网站来匹配结果。


如果我有这个字符串:


test-server::7250406f7c43524545f794ff50dfd15b

哈希是相同的:20202421c846813960404af7dd36c146. 但是如果我将字符串扩展到这个(带有编码字符):


test-server::7250406f7c43524545f794ff50dfd15b::name=%D0%98%D0%BD%D0%B5%D1%81%D1%81%D0%B0

现在散列是不同的:3db825e09eae0a83db535fda7f5ee5b5和ee1ae334e4bdeceb54caab15555f2f40。


为什么会发生这种情况?


拉丁的传说
浏览 199回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP