vfclists
vfclists

Reputation: 20211

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

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

Is using a salt the only to produce different output?

Upvotes: 40

Views: 33312

Answers (6)

Sajjad Mortazavi
Sajjad Mortazavi

Reputation: 310

Yes. Although in some cases it creates the same hash for different strings.

Upvotes: 1

Scott Stafford
Scott Stafford

Reputation: 44776

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.

Upvotes: 16

High Performance Mark
High Performance Mark

Reputation: 78316

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.

Upvotes: 1

riwalk
riwalk

Reputation: 14223

Yes. MD5 is a hash function.

This does not mean that an MD5 is unique. Multiple inputs could map to the same hash, but any given input has only one hash.

Upvotes: 1

Jim
Jim

Reputation: 22656

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

Upvotes: 46

Femaref
Femaref

Reputation: 61437

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.

Upvotes: 9

Related Questions