哈希函数如何像MD5一样独特? [英] How are hash functions like MD5 unique?

查看:127
本文介绍了哈希函数如何像MD5一样独特?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道MD5发生了一些碰撞,但这更多的是关于哈希函数的高级问题。

如果MD5将任意字符串转换为32位十六进制值,则根据 Pigeonhole Principle 当然这不能是唯一的,因为除了独特的32位十六进制值之外,还有更多独特的任意字符串。

解决方案

无法保证唯一性,但32位十六进制值(16 ^ 32)中大约有3.402823669209387e + 38个不同的值。 。这意味着,假设算法背后的算法给出了一个很好的分布,那么你的可能性就会很小,以至于会出现重复。你必须记住,当你正在考虑如何使用它的时候,它是可以复制的。通常使用MD5来确定是否有东西被改变(即,它是校验和)。

编辑:(给出最近的新闻:SHA1哈希)
答案是可笑的,不太可能的是某些东西可能会被修改并导致相同的MD5校验和。上面仍然存在,但是您不应该期望MD5哈希可以用作任何对操作的安全检查。 SHA-1哈希值为2 ^ 32(超过40亿)次碰撞的可能性较小,并且已经证明有可能设计一个输入来产生相同的值。 (相当一段时间,这是针对MD5演示的)。如果您希望确保没有人恶意修改某些内容以产生相同的哈希值,那么现在您需要在SHA-2上有一个坚实的保证。



开另一方面,如果它不在安全检查环境中,MD5仍然有用。

有人可能认为SHA-2哈希值足够便宜以至于无法计算,所以您应该直接使用它。

I'm aware that MD5 has had some collisions but this is more of a high-level question about hashing functions.

If MD5 hashes any arbitrary string into a 32-digit hex value, then according to the Pigeonhole Principle surely this can not be unique, as there are more unique arbitrary strings than there are unique 32-digit hex values.

解决方案

You're correct that it cannot guarantee uniqueness, however there are approximately 3.402823669209387e+38 different values in a 32 digit hex value (16^32). That means that, assuming the math behind the algorithm gives a good distribution, your odds are phenomenally small that there will be a duplicate. You do have to keep in mind that it IS possible to duplicate when you're thinking about how it will be used. MD5 is generally used to determine if something has been changed (I.e. it's a checksum). It would be ridiculously unlikely that something could be modified and result in the same MD5 checksum.

Edit: (given recent news re: SHA1 hashes) The answer above, still holds, but you shouldn't expect an MD5 hash to serve as any kind of security check against manipulation. SHA-1 Hashes as 2^32 (over 4 billion) times less likely to collide, and it has been demonstrated that it is possible to contrive an input to produce the same value. (This was demonstrated against MD5 quite some time ago). If you're looking to ensure nobody has maliciously modified something to produce the same hash value, these days, you need at SHA-2 to have a solid guarantee.

On the other hand, if it's not in a security check context, MD5 still has it's usefulness.

The argument could be made that an SHA-2 hash is cheap enough to compute, that you should just use it anyway.

这篇关于哈希函数如何像MD5一样独特?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆