PHP5有效的哈希生成与最小(无)碰撞机会 [英] PHP5 effecient hash generation with minimal(no) chance of collision

查看:129
本文介绍了PHP5有效的哈希生成与最小(无)碰撞机会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将用户数据存储在memcache中,而且我希望能够将用户数据存储在memcache中,而且我希望在这里存储更好的受过良好教育的人员。为用户数据生成一个唯一的。
我最初的想法是使用用户的用户名或其他较少描述性的信息作为某种散列的基础。



我的标准是生成过程将会是


  • fast

  • 在给定不同服务器的相同输入的情况下会产生相同的值/ environments / php版本

  • ,并且在给定大量输入的情况下几乎不可能发生冲突(因为这将是灾难性的)。



  • 我不确定我的平常武器sha1 / 2是否符合这个标准,所以我在这些问题上鞠躬致意。如果你的用户名是唯一的,那么你为什么不直接使用它们而不是试图生成一些它们已被保证是唯一的。

  • 可以使用它们原样。无需额外处理。

  • 它们(可能平均而言)比相应的SHA1散列小。


Cryptology isn't my thing so hopefully there are a few better educated people here than me.

I would like store user data in memcache and I'd like to generate a unique to the user data. My original idea is to use the user's username, or another less descriptive piece of information, as the basis for some kind of hash.

My criteria is that the generation process will be

  • fast
  • produce the same value given the same input across different servers/environments/php versions
  • and have little to no chance of collisions (as this would be catastrophic) given a large number of inputs.

I'm not sure whether my usual weapons, sha1/2, would fit this criteria so I'm bowing to those better verse in these matters. Better safe than sorry.

解决方案

If your usernames are unique then why don't you use them directly rather than trying to generate some kind of hash?

  • They're already guaranteed to be unique.
  • They can be used as-is. No extra processing required.
  • They'd (probably, on average) be smaller than the corresponding SHA1 hash.

这篇关于PHP5有效的哈希生成与最小(无)碰撞机会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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