MD5和序列号
我有一些很容易猜到的连续 ID。如果有人想查看与此 ID 相关的数据,他必须通过我之前给他的令牌来证明他的访问权限。
token = md5(secret_key + md5(id))
MD5 足以胜任这项工作吗?
I have some sequential id which can be easily guessed. If some want to see data related to this id he has to prove his access by token I gave him before.
token = md5(secret_key + md5(id))
Is MD5 good enough for this job?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
从技术上讲,人们甚至不需要在连接之前对 id 进行 md5 就可以保证足够的加盐安全。
不过,我通常建议使用 sha-256 或 sha-512,除非有一些严重的性能问题(例如嵌入式编程)。
Technically one does not even need to md5 the id before concatenation to be secure enough salting.
However I would generally suggest using sha-256 or sha-512 unless one has some serious performance concerns (say embedded programming).
这实际上取决于您想要保护的内容,但可能不是。我认为没有任何理由不使用更强的哈希函数。
It really depends on what you're trying to protect, but probably not. I don't see any reason not to use a stronger hashing function.
假设这用于身份验证,我将使用 HMAC。例如,请参阅 FIPS PUB 198。例如,这允许您使用安全散列函数(不是 MD5),按照描述截断结果并仍然获得安全令牌。
Assuming that this is used for authentication I'd use HMAC. See for example FIPS PUB 198. This for example allows you to use a secure hash function (not MD5), truncate the result as described and still get secure tokens.
不要使用 MD5。它坏了。我不敢相信 VeriSign 居然还有人使用 MD5。有一些测试套件可用于确定 MD5 的哈希冲突,以用于破坏 MD5 哈希比较。
至少使用 SHA-1。我建议使用 SHA-5。
Don't use MD5. It is broken. I cannot believe VeriSign of all people still use MD5. There are test suites available for determining hash collisions for MD5 for use in breaking MD5 hash comparisons.
Use, at the absolute minimum, SHA-1. I recommend using SHA-5.
如果 ID 很容易被猜到,那么这并不是非常安全,除非密钥很长。
我的电脑可以在大约一天内根据 MD5 暴力破解 6 个字符的 Secret_key 值。能够使用更快/更多计算机的人可以大大减少该时间。密钥中每增加一个数字,破解时间就会增加 10 倍。由于ID很容易被猜到,因此它是计算出的MD5值,因此并不会增加逆向获取secret_key的难度。
If the ID can be easily guessed, this is not really very secure unless the secret key is quite long.
My PC can brute-force a secret_key value based on the MD5 in about a day for a secret_key of 6 characters. People with access to faster/more computers can greatly reduce that time. The time-to-break increases by a factor of 10 for each additional digit in the key. Since the ID can be easily guessed, and therefore it's MD5 value computed, it does not add much to the difficulty of reversing to get the secret_key.
我建议使用替代解决方案,或者(如果不可接受)向您的 md5 生成例程添加更多数据。如果你的 Secret_key 是常量,并且我能够对一个哈希值进行逆向工程,那么我就可以为任何其他 ID 生成正确的密钥。
如果您在 md5 生成中构建一些内容,例如与数据一起存储的随机盐加上当前时间(如果与您正在保护的记录相关联),那么它将大大增加攻击的难度。
请参阅:
http://www.freerainbowtables.com/
I would recommend using an alternative solution, or (if not acceptable) adding more data to your md5 generation routine. If your secret_key is constant, and I am able to reverse engineer one hash, then I can generate the correct key for any other ID.
If you build something such as a random salt stored with your data plus the current time (if associated with the record you are protecting) into the md5 generation then it will dramatically increase the difficulty of the attack.
See:
http://www.freerainbowtables.com/