Maximum length for MD5 input/output
Solution 1
MD5 processes an arbitrary-length message into a fixed-length output of 128 bits, typically represented as a sequence of 32 hexadecimal digits.
Solution 2
- The length of the message is unlimited.
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.
Solution 3
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.
Solution 4
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)!
Solution 5
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.
Related videos on Youtube
Arun David
Love to solve the real world problems using technology.. I create websites and mobile apps.
Updated on July 08, 2022Comments
-
Arun David almost 2 years
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?
-
Frank over 10 yearsFollow the wiki: en.wikipedia.org/wiki/MD5
-
-
L̲̳o̲̳̳n̲̳̳g̲̳̳p̲̳o̲̳̳k̲̳̳e̲̳̳ almost 14 yearsIf 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. -
kander almost 14 yearsIts 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.
-
Your Common Sense almost 14 years@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?
-
Mark Byers almost 14 years@Col. Shrapnel: Producing a source string is good, but I'd say if he can produce an article showing how to crack it at a cost of $xxxxxxx that would also be enough.
-
Your Common Sense almost 14 years@Mark no problem, I haven't said "original source". You are free to provide any string that will produce the same hash. Money? Who said money?
Fact is that it's arbitrarily easy to find an input that generates a specific hash.
. He haven't said it will cost any money -
NikiC almost 14 yearsI actually do see a problem in using unsalted md5 for saving passwords. Fact is (and everybody may verify this using a simple Google search) that there are many providers who allow you to "crack" some of the "easier" hashes (i.e. having a short alphanumeric source string for example - exactly what you have in passwords...) I actually tried that on some of the hashes in a database and found that I can at least find 1/4 using this. So even a hobby developer having not the smallest knowledge about cryptography can find the password behind the hash - if the password is bad - which it is!
-
NikiC almost 14 yearsBut I don't want to say that using md5(md5()) or sha1() instead will fix the problem. There are providers for those, too, though far less.
-
Felix Kling almost 14 years@Col. Shrapnel: Are you a Mathematician or a Cryptographer? If not, why do you doubt the opinion of those scientists? In a mathematical sense, MD5 is definitely broken because there are methods which are faster than brute force. This might not have an impact on the daily use of MD5 yet (in a large scale). But a hash or encryption scheme has not only to be secure now but also in the future. And if there are already ways to break it, it will become even easier in the future. Of course it depends in which context you want to use MD5, but broken is broken.
-
alexbusu over 11 yearsFor SHA-1 were also found collisions(theoretical attack). See Comparison of SHA functions
-
checksum over 10 yearsNote to self: MD5 hash length =
128 bits
=16 bytes
=32 hex digits
-
JSmyth over 10 yearsNobody really mentioned what they really mean under the term "broken". Although, @YourCommonSense makes sense.
-
v1h5 over 9 years[A normal Edit] 32 hex digits and the string contains only words from 'a-z' and digits from '0-9'
-
Remis B about 9 yearsI 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'"
-
Salami over 8 yearsHashes aren't only used for security.
-
Aydin K. about 8 yearsor:
128 bits = 32 hex digits * 4bit
-
Shafizadeh about 8 yearsThe length of the message is unlimited, What do you mean message? Is it input? My question is
MD5("how many characters exactly?");
-
Shafizadeh about 8 yearsMay you please tell me how many characters exactly can be as MD5's input?
MD5("how many characters can be in here?");
-
kdojeteri about 8 years@Shafizadeh As the answer states, the input has an arbitrary length. This means the parameter can be any length you need.
-
tfrascaroli over 7 yearsYou 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.
-
RicoBrassers over 7 years@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. ;)
-
RicoBrassers over 7 years@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.
-
RicoBrassers over 7 yearsMD5 is considered broken/insecure and should not be used for critical stuff like passwords in databases anymore. It can still be used for file checksums, though.
-
ToolmakerSteve almost 7 yearsFWIW - @RicoBrassers - I suppose you were making a tongue-in-cheek comment, because OP mentioned an input "string", but I'd like to point out that input could be as large as desired in practice, not just in theory. For example, a Java function could take as input the name of a file. That file could be as large as available storage; not limited by any datatype. It could even be from some streaming source, that far exceeds available local storage. Just saying. :P
-
ToolmakerSteve almost 7 years@Shafizadeh ... or from a file, the input could be as large as available storage.
-
RicoBrassers almost 7 years@ToolmakerSteve Well, it depends on your implementation. If your hash function supports streaming data, then you're correct, obviously. While the hashing algorithm itself shouldn't have a limitation in theory, the practical implementation itself might have some form of limitation. Thank you for the heads up. ;)
-
ntg over 6 yearsThat depends on the use. The question does not say what the use of the hash will be. MD5 is not considered broken. It is however completely unsuitable for passwords etc. as it is NOT used as a CRYPTOGRAPHIC hash function in any modern sense. It is however extremely faster than SHA1, and so is a very nice one to use if we just care about e.g. finding an insecure cache file name or creating a fast hash lookup for e.g counting, checksums etc. It does its job very well, however this job is not security related. – ntg 1 min ago edit
-
jinawee almost 6 yearsHow does this answer the question?
-
MARCILIO DACOL NETO almost 3 yearsthat would be 18 exabits or 18 e3 petabits or 18 e6 terabits or 18 e9 Gigabits.