php 安全性:使用 MD5、SHA1、Salting

发布于 2024-08-06 00:26:39 字数 309 浏览 11 评论 0原文

目前,我的许多密码都是以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泪痕残 2024-08-13 00:26:39

有几点:

  1. 只需使用 SHA256 - 无需重新散列。

  2. 不要只为每个帐户硬编码一个盐。为每个用户生成一个随机盐并将其放入数据库中的用户记录中。这样,如果有人为该盐生成彩虹表,至少他们只能访问该一个用户帐户,而不是所有用户帐户。

A couple things:

  1. Just use SHA256 - don't bother re-hashing.

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

携君以终年 2024-08-13 00:26:39

更多不一定更好。只需使用 Sha256 即可完成。

$var = $var.'t00lup';
$hashedPass=hash('sha256', $var);

此处了解有关 hash() 的更多信息。

More is not necessarily better. Just use Sha256 and be done with it.

$var = $var.'t00lup';
$hashedPass=hash('sha256', $var);

Read more about hash() here.

菩提树下叶撕阳。 2024-08-13 00:26:39

使用盐是绝对必要的,因为否则,攻击者可以使用现有的预计算表来简单地查找用户使用过的所有短密码或字典密码的哈希值。您可以自己尝试一下:获取非常糟糕的(短密码或字典密码)密码的 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.

萌逼全场 2024-08-13 00:26:39

VBulletin 使用类似 md5(md5($password).$salt) 的东西。看起来还可以。

VBulletin uses something like md5(md5($password).$salt). Seem to be ok.

悟红尘 2024-08-13 00:26:39

我认为做一些加盐可以提高安全性,因为它使字典攻击变得更加困难,而且即使密码很短,整个安全级别仍然可以。

最重要的是哈希算法和生成的哈希的长度,因此您最好研究 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文