Question

Will changing a file name effect the MD5 Hash of a file?

Was it helpful?

Solution

Only if the file's name was included in the hash calculation. e.g., in pseudo-code:

$hash1 = md5(contents of file);
$hash2 = md5(name of file + contents of file);

will produce two seperate hashes.

OTHER TIPS

No, the hash is of the file contents only. You can see this in the source for md5sum and its MD5 implementation. You can also test this if you have access to md5sum:

$ echo "some arbitrary content" > file1
$ cp file1 file2
$ md5sum file1
f0007cbddd79de02179de7de12bec4e6  file1
$ md5sum file2
f0007cbddd79de02179de7de12bec4e6  file2
$

In Linux using EXT filesystem, it will not, because a file name is not stored in a file, it is stored in the directory entry (dentry) that the file lives in, where the inode of the file is then mapped to a name. Changing a filename will have no affect on its md5sum in Linux. In Windows, I cannot be sure.

If the hash is computed from the file contents, it shouldn't.

In ESXi (Precisely ESXi 5.5) md5sum on same content but different file names is different. That leads me to believe that VMFS-5 file structure includes file name too. If we are not concerned about file name, Is there a way to check only the md5sum of file content? I couldn't see any option. Any suggestions?

1.md5 is calculated based on binary content of the FILE. 2.File name,last modified etc. things are meta data.md5 not really rely on meta-data. I have tested this with below steps,lets work with "last modified" meta-data i)I have created a file named "a.txt" and added some content and created a hash say hash is "xyz" ii)Then I have just added a space in the file and again calculated the hash say it returned "abc" iii)I just removed my change in step (ii),on calculating hash again I have got the initial hash("xyz")

This concludes that even though the metadata of file is changed,the hash remains same till the file content remains unaltered.

Hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top