How to change MD5 of a file

Solution 1:

md5sum calculates and verifies 128-bit MD5 hashes. The MD5 hash functions as a compact digital fingerprint of a file. It is very unlikely that any two non-identical files in the real world will have the same MD5 hash, unless they have been specifically created to have the same hash.

md5sum is used to verify the integrity of files, as virtually any change to a file will cause its MD5 hash to change. Most commonly, md5sum is used to verify that a file has not changed as a result of a faulty file transfer, a disk error or non-malicious meddling.

For more see Wikipedia

Could it be changed?

No. You can not change md5sum of a file as long as the contents of the files are same. And that is the sole purpose of it. You can change the md5sum value of a file by making any change in its content only.

Solution 2:

md5sum calculates MD5 hash of file contents. MD5 algorithm doesn't use any randomness (it's deterministic). It's basically a list of mathematical instructions to perform on the input (file contents). Every time you provide it with the same input, it processes it in exactly the same way and you get the same output. Just like maths: 3×7 will always yield 21, no matter how many times you try.

The only way to change output is to change the input.

Solution 3:

While I agree with @sauravc, there is a way to do it if you don’t mind the possibility of corrupting the file.

If you change the file in any way, you can recalculate the MD5.

You can potentially change a file by opening it in your preferred editor, making an addition or subtraction, then saving it again.

If you want a quick way to do this via command line, you can use either dd or truncate like this:

dd if=/dev/zero bs=1 count=10 >> <yourfile>.<ext>

or

truncate -s +10 <yourfile>.<ext>

Either command should add 10 bytes to the end of your file. This should mean the MD5 (when next calculated) should be different.

Beware

This has the potential to corrupt your files, and should be tested thoroughly first.