Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a file with a given size and MD5 hash?

Tags:

c#

security

hash

Of course I know is possible to create a file with a certain size and how to do it. But is it possible to create a file with a certain size and also a certain MD5 fingerprint?

like image 748
ccalboni Avatar asked Mar 25 '10 15:03

ccalboni


People also ask

Can you create a file from a hash?

It is possible to create a file given a hash value. However, if you have a file and create a MD5 hash this process will not recreate that file but create a small file filled with gibberish.

What is the size of a MD5 hash value?

The hash size for the MD5 algorithm is 128 bits. The ComputeHash methods of the MD5 class return the hash as an array of 16 bytes. Note that some MD5 implementations produce a 32-character, hexadecimal-formatted hash.

Can you change the MD5 hash of a file?

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.


3 Answers

Not being able to find a file with a certain hash is one of the defining properties of a cryptographic hash function such as md5.

While md5 has been broken, those breaks only allow you to create two different files (images) with the same hash, but not with a predetermined hash.

What you want is called a pre-image attack, and since md5 is still unbroken concerning that attack, you need to bruteforce.

This requires 264 (2128/2) hashing operations on average, which is far beyond anything we can get with current computers.

Wikipedia has an article on pre-image attacks too:
http://en.wikipedia.org/wiki/Preimage_attack

like image 107
Winner Avatar answered Oct 13 '22 01:10

Winner


Just creating a file with a given MD5 hash is difficult enough without adding the size requirement.

You could try a rainbow table, but that requires a long time to create and a huge amount of memory to store.

like image 32
Michael Myers Avatar answered Oct 13 '22 01:10

Michael Myers


Theoretically, yes. Practically, it will most likely require computation of all permutations of all n bytes in a file -- baiscally, brute-forcing. Which means, this is hardly doable in any reasonable timeframe.

like image 27
Anton Gogolev Avatar answered Oct 12 '22 23:10

Anton Gogolev