php 安全性:使用 MD5、SHA1、Salting
目前,我的许多密码都是以 md5 和 sha1 的混合形式存储的,但我刚刚接触过 salting,并且想知道什么是最安全的。
我确信简单的 md5() 可以很容易地被撤销,但是 md5(sha1(md5($var))); 怎么样?这个组合是否提供了更多的难度,或者更多不一定更好。
另外,
$var = $var.'t00lup';
md5($var);
假设 t00lup 是私钥,这样做是否比上面更安全?
除了使用 md5 或 sha1 之外,还有更好的方法吗?
谢谢
Currently Many of my passwords are stored with a mixture of md5's and sha1's however I've just been introduced to salting, and wanted to know the breakdown of what might be the most secure.
I'm certin that a simple md5() can easily be revoked, however what about md5(sha1(md5($var))); Does this combo provide more difficulty, or is more not necessarily better.
Also, is doing
$var = $var.'t00lup';
md5($var);
more secure than the above, assuming t00lup is a private key?
Is there a better way of doing this instead of just using md5 or just using sha1?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有几点:
只需使用 SHA256 - 无需重新散列。
不要只为每个帐户硬编码一个盐。为每个用户生成一个随机盐并将其放入数据库中的用户记录中。这样,如果有人为该盐生成彩虹表,至少他们只能访问该一个用户帐户,而不是所有用户帐户。
A couple things:
Just use SHA256 - don't bother re-hashing.
Don't just hardcode a single salt for every account. Generate a random salt for each user and put it on their user record in the database. That way if someone generates a rainbow table for that salt, at least they would only get access to that one user account rather than all of them.
更多不一定更好。只需使用 Sha256 即可完成。
此处了解有关 hash() 的更多信息。
More is not necessarily better. Just use Sha256 and be done with it.
Read more about hash() here.
使用盐是绝对必要的,因为否则,攻击者可以使用现有的预计算表来简单地查找用户使用过的所有短密码或字典密码的哈希值。您可以自己尝试一下:获取非常糟糕的(短密码或字典密码)密码的 MD5,然后在 google 上搜索结果 - 很可能您会在某个地方找到结果。
有了盐,现有的表就变得毫无用处,并且除了最足智多谋和最积极的攻击者之外,计算自己的表需要花费太长时间。每个用户的单独盐甚至更好(否则知道盐的攻击者可以立即攻击所有用户)。
组合哈希可能会产生类似的效果,但不应该用于此目的(没有盐),因为该组合仍然可能存在预先计算的表。
然而,散列的组合和重复有其自身的价值,它增加了攻击者进行字典攻击所需的时间:应用 MD5 一万次仍然需要几分之一秒的时间,并且作为登录的一部分是可行的过程。但对于字典攻击来说,花费 10,000 倍的时间是一个问题。
这种技术称为密钥强化。
Using a salt is absolutely required, because otherwise, an attacker can use existing precomputed tables to simply look up hashes for all short or dictionary passwords your users have used. You can try this yourself: take the MD5 of a very bad (short or dictionary) password and do a google search for the result - most likely you'll get a hit somewhere.
With a salt, existing tables become useless, and computing your own takes too long for all but the most resourceful and motivated attackers. Individual salts for each user are even better (otherwise an attacker who knows the salt can attack all your users at once).
Combining hashes could have a similar effect, but should not be used for that purpose (without a salt) because it's still possible for a precomputed table to exist for that combination.
However, the combination and repetition of hashes has a value of its own, by increasing the time it takes for an attacker to do a dictionary attack: applying MD5 ten thousand times still takes a fraction of a second and is feasible as part of the login process. But for a dictionary attack, taking 10,000 times as long is a problem.
This technique is known as key strengthening.
VBulletin 使用类似 md5(md5($password).$salt) 的东西。看起来还可以。
VBulletin uses something like md5(md5($password).$salt). Seem to be ok.
我认为做一些加盐可以提高安全性,因为它使字典攻击变得更加困难,而且即使密码很短,整个安全级别仍然可以。
最重要的是哈希算法和生成的哈希的长度,因此您最好研究 sha256 或更好的算法。
I think doing some salting improve security since it make dictionary attack more difficult and also even If the password is short the whole security level is still ok.
The most important things is really the hashing algorithm and the lenght of the resulting hash so you have better to look into sha256 or better.