简体   繁体   中英

Is a MD5 hash of a file unique on every system?

... operating system, file system, etc.

Or are there cases, where the hash differs?

The hash of a bit string is the same regardless of operating system, file system etc. It is the product of a series of mathematical operations on that string.

However, be advised that this holds only for files that are identical bit-by-bit. For instance, most text files on Windows have \\r\\n as line breaks, whereas on Linux it is usually only \\n . There could also be differences in the encoding of text files.

In other words, hash algorithms tell if two files are binarily equal, not if they are semantically equal.

Also, be careful when using MD5. It is broken beyond repair. You should almost certainly be using a newer algorithm, such as SHA256.

MD5 is well-defined for a particular input. If the file contents are the same, then the MD5 will be the same across systems.

The reverse it not necessarily true - if two files have the same MD5 hash, they could have different contents, though the probability of this is very low.

However, it should be noted that for collisions have been intentionally created for MD5 hashes, so the cryptographic security of MD5 is considered broken ( http://en.wikipedia.org/wiki/MD5#Collision_vulnerabilities ). I'm not a security expert, therefore I'm not sure how vulnerable MD5 is in the real world at the moment. But, since there are other hash algorithms available, they should be used instead of MD5 if you have the option.

md5 hashing algorithm is not supposed to depend on operating and/or file systems.

md5 hashing depends only on file contents .. a collision can happen in very rare cases like this

MD5是一种算法,这意味着它独立于运行它的系统。

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