Aron Woost
Aron Woost

Reputation: 20688

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

... operating system, file system, etc.

Or are there cases, where the hash differs?

Upvotes: 3

Views: 3895

Answers (4)

Michael Burr
Michael Burr

Reputation: 340436

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.

Upvotes: 6

Pepe
Pepe

Reputation: 6480

MD5 is an algorithm which means it is independent of the system on which it runs.

Upvotes: 0

Ahmed Kotb
Ahmed Kotb

Reputation: 6307

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

Upvotes: 1

Pedro d'Aquino
Pedro d'Aquino

Reputation: 5230

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.

Upvotes: 9

Related Questions