196

What is the maximum length of the string that can have md5 hashed? Or: If it has no limit, and if so what will be the max length of the md5 output value?

1

9 Answers 9

287

MD5 processes an arbitrary-length message into a fixed-length output of 128 bits, typically represented as a sequence of 32 hexadecimal digits.

Sign up to request clarification or add additional context in comments.

12 Comments

Note to self: MD5 hash length = 128 bits = 16 bytes = 32 hex digits
[A normal Edit] 32 hex digits and the string contains only words from 'a-z' and digits from '0-9'
I noticed a little mistake in previous comments. Text should be as quoted :) "32 hex digits and the string contains only letters from 'a-z' and digits from '0-9'"
@Shafizadeh As the answer states, the input has an arbitrary length. This means the parameter can be any length you need.
@Peping A small correction: The input can be as long as the used datatype in the programming language used can be. Example: Java's strings use an array internally, therefore, a string can only contain (2^31)-1 characters (or less, depending on the heap size).That would also be your maximum input for the MD5 function in Java. But pure theoretically, the MD5 function could process indeed an input of arbitrary length. ;)
|
46

Append Length

A 64-bit representation of b (the length of the message before the padding bits were added) is appended to the result of the previous step. In the unlikely event that b is greater than 2^64, then only the low-order 64 bits of b are used.

  • The hash is always 128 bits. If you encode it as a hexdecimal string you can encode 4 bits per character, giving 32 characters.
  • MD5 is not encryption. You cannot in general "decrypt" an MD5 hash to get the original string.

See more here.

3 Comments

The length of the message is unlimited, What do you mean message? Is it input? My question is MD5("how many characters exactly?");
@Shafizadeh Your input can be as long as possible in your current programming language, in Java this would be (2^31)-1 characters in a string. And yes, the "message" is the input.
@Shafizadeh ... or from a file, the input could be as large as available storage.
15

You can have any length, but of course, there can be a memory issue on the computer if the String input is too long. The output is always 32 characters.

1 Comment

If the string input is too long it wouldn't exist in the system in the first place, unless it's in a file, in which case you can pass in blocks to the digest function as they are read, in other words, you only need to have block bytes of the input available at a time.
8

The algorithm has been designed to support arbitrary input length. I.e you can compute hashes of big files like ISO of a DVD...

If there is a limitation for the input it could come from the environment where the hash function is used. Let's say you want to compute a file and the environment has a MAX_FILE limit.

But the output string will be always the same: 32 hex chars (128 bits)!

1 Comment

Even if you want to compute the hash of a file, and somehow (how?) the file is larger than MAX_FILE, you still can compute the hash. Feed a first chunk of permissible size to the hash function, then update with another, and so on, until you are done; then you ask for the digest result.
4

A 128-bit MD5 hash is represented as a sequence of 32 hexadecimal digits.

Comments

4

You may want to use SHA-1 instead of MD5, as MD5 is considered broken.

You can read more about MD5 vulnerabilities in this Wikipedia article.

14 Comments

Its creator, as well as Bruce Schneier and Homeland Security are in agreement that it's broken... How many more 'rumorspreading' do you need to convince you that it's actually been broken for some time? Fact is that it's arbitrarily easy to find an input that generates a specific hash. Of course you can mitigate this risk by salting your inputs, using sufficiently large salts. On a side-note: SHA-1 is considered to be just as broken. If you advise people to upgrade, advise them to upgrade to SHA-2, please.
@kander oh I need a very little. An example. Given a hash, will you bring a source string? Not a link to some great article, not someone's opinion but just a source string?
Nobody really mentioned what they really mean under the term "broken". Although, @YourCommonSense makes sense.
Hashes aren't only used for security.
You are talking about security uses of MD5. But MD5 (or any other hashing technique) has a ton of other uses. I, for one, want to use it to rename a file by its hash. I'm surely not concerned about the collision resistance of MD5. Everything you posted is still true, just my 2 cents.
|
3

There is no limit to the input of md5 that I know of. Some implementations require the entire input to be loaded into memory before passing it into the md5 function (i.e., the implementation acts on a block of memory, not on a stream), but this is not a limitation of the algorithm itself. The output is always 128 bits. Note that md5 is not an encryption algorithm, but a cryptographic hash. This means that you can use it to verify the integrity of a chunk of data, but you cannot reverse the hashing. Also note that md5 is considered broken, so you shouldn't use it for anything security-related (it's still fine to verify the integrity of downloaded files and such).

Comments

2

md5 algorithm appends the message length to the last 64 bits of the last block, thus it would be fair to say that the message can be 2^64 bits long (18 e18 bits).

1 Comment

that would be 18 exabits or 18 e3 petabits or 18 e6 terabits or 18 e9 Gigabits.
0

Max length for MD5 input : largest definable and usable stream of bit A stream of bit definition constraints can depend on operating system, hardware constraints, programming language and more...

Length for MD5 output : Fixed-length always 128 bits For easier display, they are usually displayed in hex, which because each hex digit (0-1-2-3-4-5-6-7-8-9-A-B-C-D-E-F) takes up 4 bits of space, so its output can be displayed as 32 hex digits. 128 bits = 16 bytes = 32 hex digits

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.