简体   繁体   中英

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

And the second file is: http://xzerox.info/servconfig.php

However, when I use md5_file() to get their MD5, They return two different MD5's.

The first returns cc7819055cde3194bb3b136bad5cf58d , which is incorrect, and the second returns 96a0cec80eb773687ca28840ecc67ca1 , which is correct.

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   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):

$ 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 :)

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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