We can get MD5 of a file by using md5sum so my questions are:

  1. Could the MD5 be changed?
  2. How to change the MD5?
  • 8
    By changing the file? – immibis Dec 3 '16 at 8:42
  • 2
    @ThomasPadron-McCarthy don't leave malicious commands as comments with no explanation. Not cool. – terdon Dec 3 '16 at 13:47
  • 1
    @terdon What was the command, so we know? – NoOneIsHere Dec 3 '16 at 22:31
  • 1
    As a side note: If you are using MD5 as a simple check against changes, that's fine. But if security is a significant issue, MD5 is no longer considered sufficiently secure, in which case SHA (e.g. sha512) would be better. – Paddy Landau Dec 6 '16 at 9:27
  • There are also two counter-question. 1. Do you know what is MD5? 2. What are your reasons to change it? – Dávid Horváth Apr 6 '17 at 15:41

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.

  • Thank you. But I found a tool(on window) and it can change MD5 of a file. – Rong Nguyen Dec 3 '16 at 4:41
  • 6
    You are welcome. But surely it is changing any file may be slightly. You never know the file will work as before or not. In the process there is always a chance of file corruption. – souravc Dec 3 '16 at 4:47
  • just pad a few null bytes at the end of the file – Tschallacka Dec 3 '16 at 8:15
  • 1
    @Tschallacka If the file is a script this would probably raise a syntax error, rendering the script useless.. – Bakuriu Dec 3 '16 at 15:31
  • 4
    @Tschallacka: Whether that works depends entirely on the file format and/or the leniency of its decoder. Many binary formats ignore trailing null bytes, many others don't. Text-based file formats will probably stop working if you append null bytes. – David Foerster Dec 3 '16 at 16:58

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.


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>


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.


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

protected by souravc Dec 8 '16 at 4:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.