Does the MD5 algorithm always generate the same output for the same string?

23,548

Solution 1

Yes, otherwise MD5 would be useless for things like file verification. What reason would you have for non deterministic output?

Solution 2

Yes, MD5 always outputs the same given the same input. That's how it's used for passwords. You store the hash in the database, then when the user types their password in, it's hashed again and the two hashes are compared.

NOTE: MD5 is not recommended for hashing passwords because it's cryptographically weak. There are more suitable cryptographic hashes available, such as bcrypt. However, historically, it has been used for this purpose.

Solution 3

Yes, a hash algorithm always produces the same output. If you use the same salt, this will also always produce the same output for a given input.

Solution 4

Yes MD5 is deterministic, and this is considered a desirable characteristic for many applications of message digest functions.

As for using a salt, by that you really mean 'changing the input string in some subtle way' don't you ? And, of course, it is also a desirable characteristic of message digests that they produce (with very high probability) a different digest for a different message.

Share:
23,548
vfclists
Author by

vfclists

Updated on October 11, 2020

Comments

  • vfclists
    vfclists over 3 years

    Does the MD5 algorithm always generate the same output for the same string?

    Is using a salt the only to produce different output?