简体   繁体   English

为什么相同的输入返回两个不同的MD5哈希值?

[英]Why is the same input returning two different MD5 hashes?

Alright, I have two files. 好吧,我有两个文件。 They are the EXACT SAME. 他们是完全相同的。

The first file is: http://iadsonline.com/servconfig.php 第一个文件是: http://iadsonline.com/servconfig.phphttp://iadsonline.com/servconfig.php

And the second file is: http://xzerox.info/servconfig.php 第二个文件是: http://xzerox.info/servconfig.phphttp://xzerox.info/servconfig.php

However, when I use md5_file() to get their MD5, They return two different MD5's. 但是,当我使用md5_file()来获取他们的MD5时,他们会返回两个不同的MD5。

The first returns cc7819055cde3194bb3b136bad5cf58d , which is incorrect, and the second returns 96a0cec80eb773687ca28840ecc67ca1 , which is correct. 第一个返回cc7819055cde3194bb3b136bad5cf58d ,这是不正确的,第二个返回96a0cec80eb773687ca28840ecc67ca1 ,这是正确的。

The file is simply an   该文件只是一个 

To verify, I've used this code: 为了验证,我使用了这段代码:

$contents = file_get_contents($URL);
echo htmlentities($contents);

And they both return   他们都返回 

So why is it hashing them differently? 那么为什么它们以不同的方式散列呢?

第二个以换行符结束,第一个不换行。

Trying with curl , I see the first one is   尝试curl ,我看到第一个是  without a newline after it, the second one is   在没有换行后,第二个是  with a newline after it. 后一个换行符。 So of course they'll hash differently. 所以他们当然会以不同的方式散列。 And indeed, even at the command line (bash prompt): 事实上,即使在命令行(bash提示符):

$ md5 sc.dat 
MD5 (sc.dat) = cc7819055cde3194bb3b136bad5cf58d
$ md5 zz.dat
MD5 (zz.dat) = 96a0cec80eb773687ca28840ecc67ca1

this also happened with me. 这也发生在我身上。 I set the same encoding (utf-8 without BOM) to all files that store and retrieve hashed strings :) now md5() gives the same results :) 我将相同的编码(utf-8没有BOM)设置为存储和检索散列字符串的所有文件:)现在md5()给出了相同的结果:)

Could you have whitespace in either of those files? 你能在这两个文件中都有空格吗? Open them up in a text editor and show all characters . 在文本编辑器中打开它们并显示所有字符

Alternatively, run something like this 或者,运行这样的东西

echo str_replace(array("\n", "\t", "\r"), '[I AM HIDING!]', file_get_contents($URL));

If you see [I AM HIDING!] , you will know what to do :) 如果你看到[我在讨厌!] ,你会知道怎么做:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM