MD5上15个字符字母数字字符串的碰撞概率

时间:2017-04-06 16:10:47

标签: php cryptography md5 hash-collision

我正在生成15个字符的字母数字代码,并将它们保存为MD5哈希以进行保护。但是我不能有非唯一或碰撞的哈希值,如果它们出现,我不会插入它们。由于我在应用程序的生命周期内将大量代码插入到数据库中,并且为了确保应用程序的更好性能,我希望确保碰撞本身的数量更少。

问题: 如果输入空间增加到15,那么碰撞的概率是多少? (36因为我使用了26个小写字母和10个数字和15个,因为我生成了15个这样的代码)。

您可以在这里参考,了解我是如何生成代码的。

用法:在优惠券代码中使用这些,我想哈希它们以保护自己免受数据库泄露。

1 个答案:

答案 0 :(得分:1)

The chances of generating a collision any collision of a secure hash are negligible, i.e. close to zero. That's even true for MD5, which is a broken secure hash. Even with a very large input (think 2^64) of hashes, the chances of generating a collision is still about 1/(2^64).

The possibility of your input having a collision is of course much higher (assuming that it is randomly generated), as 36^15 is much smaller than 2^128, the output size of MD5 (36^15 < (2^6)^15 = 2^90 <<< 2^128). So there are fewer input values than that there are hash values.