Is there a greater chance to collide when comparing GUIDs based on a hash vs "Guid.NewGuid()?

末鹿安然 提交于 2019-12-11 00:48:25

问题


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())?


回答1:


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.



来源:https://stackoverflow.com/questions/35701564/is-there-a-greater-chance-to-collide-when-comparing-guids-based-on-a-hash-vs-gu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!