2

A follow-up to Is there a greater chance to collide when comparing GUIDs created differently?.

I have something like this:

using( MD5 md5 = MD5.Create() ) {
    var hash = md5.ComputeHash( foo );
    var hashguid = new Guid( hash );
}

This guarantees the same foo will cause a GUID collision, and allows filtering of duplicates of foo.

Is there any concerns that hashguid has a greater chance to collide with GUIDs generated with Guid.NewGuid() (vs. two GUIDs generated with Guid.NewGuid())?

Community
  • 1
  • 1
neverendingqs
  • 4,006
  • 3
  • 29
  • 57
  • i wouldn't imagine there would be if you are talking a single guid created with the hash, vs two guids created via `Guid.NewGuid()`. You are still talking about astronomical odds of collision, so it would be largely academic. – user1666620 Feb 29 '16 at 14:05
  • 2
    It is neither fish nor fowl, the argument you pass to the Guid constructor must already be a guid. The MD5 hash is not actually a guid but the Guid type does not check that. You do *not* get the guarantee that Guid provides, an MD5 hash is not globally unique. – Hans Passant Feb 29 '16 at 14:10
  • Possible duplicate of [Is there more chance having collisions between GUID's or a SHA1 hashes of GUID's?](https://stackoverflow.com/questions/14861313/is-there-more-chance-having-collisions-between-guids-or-a-sha1-hashes-of-guids) – Michael Freidgeim Nov 20 '17 at 11:30

1 Answers1

0

Cryptographically strong hash algorithms do not increase the chance of collision significantly when compared to the chance of collision for the hash input. This is safe.

There is no practical reduction of collision risk by structuring a guid in a certain way. The collision chance of randomly generated guids is so low that even the Mars Rover can rely on that not to happen.

MD5 is a broken algorithm and I would not call it cryptographically strong. I don't understand why people still use MD5. Isn't this common knowledge 10 years after the breaking?! Consider using SHA256 and truncating the output to 128 bits.

usr
  • 168,620
  • 35
  • 240
  • 369