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

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

问题描述

我知道 MD5 有一些冲突,但这更多是关于散列函数的高级问题.

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

如果 MD5 将任意字符串散列成 32 位十六进制值,则根据 Pigeonhole Principle 这当然不可能是唯一的,因为唯一的任意字符串比唯一的 32 位十六进制值多.

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.

推荐答案

您说得对,它不能保证唯一性,但是在 32 位十六进制值 (16^32) 中大约有 3.402823669209387e+38 个不同的值.这意味着,假设算法背后的数学给出了一个很好的分布,你的几率非常小,会出现重复.您必须记住,当您考虑如何使用它时,可以进行复制.MD5 通常用于确定某些内容是否已更改(即校验和).修改某些内容并导致相同的 MD5 校验和是非常不可能的.

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.

(鉴于最近的新闻:SHA1 哈希)上面的答案仍然成立,但您不应该期望 MD5 哈希可以作为任何类型的针对操纵的安全检查.SHA-1 哈希的碰撞可能性降低了 2^32(超过 40 亿)倍,并且已经证明可以设计输入以产生相同的值.(这在很久以前就已针对 MD5 进行了证明).如果您想确保没有人恶意修改某些内容以产生相同的哈希值,那么现在,您需要在 SHA-2 中获得可靠的保证.

(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.

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

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

可以认为 SHA-2 哈希值足够便宜以进行计算,因此无论如何您都应该使用它.

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天全站免登陆