多次加密(MD5)可以提高安全性吗?
我看到有人用 MD5 对用户密码进行多次加密以提高安全性。我不确定这是否有效,但看起来不太好。那么,这有意义吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我看到有人用 MD5 对用户密码进行多次加密以提高安全性。我不确定这是否有效,但看起来不太好。那么,这有意义吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
我们假设您使用的哈希函数是一个完美的单向函数。然后你可以像"random oracle"一样查看它的输出,它的输出值在一个值的有限范围(MD5 为 2^128)。
现在,如果多次应用哈希会发生什么?输出仍将保持在相同范围内 (2^128)。就像你说“猜猜我的随机数!”二十次,每次都想一个新的数字——这并不会让猜测变得更难或更容易。没有比随机更“随机”的了。这不是一个完美的类比,但我认为它有助于说明问题。
考虑到暴力破解密码,您的方案根本不会增加任何安全性。更糟糕的是,您唯一可以“完成”的事情就是通过引入一些利用哈希函数重复应用的可能性来削弱安全性。虽然可能性不大,但至少可以保证你不会赢得任何东西。
那么为什么这种方法仍然没有迷失呢?这是因为其他人提出的想法是进行数千次迭代,而不是仅仅 20 次。为什么这是一件好事,可以减慢算法速度?这是因为大多数攻击者会尝试使用字典(或使用常用密码的 rainbow 表 来获取访问权限,希望你的一个用户疏忽大意地使用了其中一个(我有罪,至少 Ubuntu 在安装时告诉我),但另一方面,要求你的用户记住 30 是不人道的。 。
这就是为什么我们需要在易于记住的密码和同时让攻击者尽可能难以猜测之间进行某种形式的权衡。有两种常见的做法,salts 并通过应用某些函数的大量迭代而不是单次迭代来减慢进程。
href="http://www.rsa.com/rsalabs/node.asp?id=2127" rel="noreferrer">PKCS#5 是您应用 MD5 20000 的 而不是 20 次,会显着降低攻击者使用字典的速度,因为他们的每个输入密码都必须经过哈希 20000 次的普通过程,才能仍然作为攻击有用。请注意,此过程不会影响如上所示的暴力破解。
但为什么使用盐更好呢?因为即使您应用哈希 20000 次,足智多谋的攻击者也可以预先计算大型密码数据库,对每个密码进行哈希 20000 次,从而有效地生成专门针对您的应用程序的自定义彩虹表。完成此操作后,他们可以很容易地攻击您的应用程序或使用您的方案的任何其他应用程序。这就是为什么您还需要为每个密码生成较高的成本,以使此类彩虹表使用起来不切实际。
如果您想真正安全,请使用 PKCS#5 中所示的 PBKDF2 之类的东西。
Let's assume the hash function you use would be a perfect one-way function. Then you can view its output like that of a "random oracle", its output values are in a finite range of values (2^128 for MD5).
Now what happens if you apply the hash multiple times? The output will still stay in the same range (2^128). It's like you saying "Guess my random number!" twenty times, each time thinking of a new number - that doesn't make it harder or easier to guess. There isn't any "more random" than random. That's not a perfect analogy, but I think it helps to illustrate the problem.
Considering brute-forcing a password, your scheme doesn't add any security at all. Even worse, the only thing you could "accomplish" is to weaken the security by introducing some possibility to exploit the repeated application of the hash function. It's unlikely, but at least it's guaranteed that you for sure won't win anything.
So why is still not all lost with this approach? It's because of the notion that the others made with regard to having thousands of iterations instead of just twenty. Why is this a good thing, slowing the algorithm down? It's because most attackers will try to gain access using a dictionary (or rainbow table using often-used passwords, hoping that one of your users was negligent enough to use one of those (I'm guilty, at least Ubuntu told me upon installation). But on the other hand it's inhumane to require your users to remember let's say 30 random characters.
That's why we need some form of trade-off between easy to remember passwords but at the same time making it as hard as possible for attackers to guess them. There are two common practices, salts and slowing the process down by applying lots of iterations of some function instead of a single iteration. PKCS#5 is a good example to look into.
In your case applying MD5 20000 instead of 20 times would slow attackers using a dictionary significantly down, because each of their input passwords would have to go through the ordinary procedure of being hashed 20000 times in order to be still useful as an attack. Note that this procedure does not affect brute-forcing as illustrated above.
But why is using a salt still better? Because even if you apply the hash 20000 times, a resourceful attacker could pre-compute a large database of passwords, hashing each of them 20000 times, effectively generating a customized rainbow table specifically targeted at your application. Having done this they could quite easily attack your application or any other application using your scheme. That's why you also need to generate a high cost per password, to make such rainbow tables impractical to use.
If you want to be on the really safe side, use something like PBKDF2 illustrated in PKCS#5.
散列密码不是加密。这是一个单向过程。
查看 security.stackexchange.com 以及与密码相关的问题。它们非常受欢迎,我们将其放在一起 这篇博文专门帮助个人找到有用的问题和答案。
这个问题专门讨论了连续使用 md5 20 次 - 查看 Thomas Pornin 的回答。他的回答要点:
Hashing a password is not encryption. It is a one-way process.
Check out security.stackexchange.com, and the password related questions. They are so popular we put together this blog post specifically to help individuals find useful questions and answers.
This question specifically discusses using md5 20 times in a row - check out Thomas Pornin's answer. Key points in his answer:
crypto.SE 上有这样一个问题,但现在不公开。 Paŭlo Ebermann 的答案是:
类似的问题有以下答案:
问题是“防范密码分析突破:组合多个哈希函数”
Thomas Pornin 的回答:
并通过 PulpSpy:
There is such a question on crypto.SE but it is NOT public now. The answer by Paŭlo Ebermann is:
And similar question has these answers:
The question is "Guarding against cryptanalytic breakthroughs: combining multiple hash functions"
Answer by Thomas Pornin:
And by PulpSpy:
不,这不是一个好的做法,您必须使用 $salt 进行加密,因为密码可以用那些彩虹表破解
no , it's not a good practice, you must use a $salt for your encryption because the password cand be cracked with those rainbow tables