简体   繁体   English

加密密码?

[英]Encryption of hashed passwords?

I came about this security discussion after reading some topics about session management in php, have a look: https://paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title.2 在阅读了有关php中会话管理的一些主题之后,我开始进行这个安全性讨论,看看: https//paragonie.com/blog/2015/04/secure-authentication-php-with-long-term-persistence#title。 2

Quote from Chapter: To Pepper Or Not To Pepper? 引用章节: 胡椒还是胡椒?

A much better solution, which is especially useful if you employ hardware separation, is to encrypt the hashes before you insert them in your database. 一个更好的解决方案,在使用硬件分离时尤其有用,是在将哈希值插入数据库之前加密哈希值。 With this safeguard in place, even if an attacker finds a way to dump all of your database tables, they first have to decrypt the hashes before they can even begin to crack them. 有了这个安全措施,即使攻击者找到了转储所有数据库表的方法,他们首先必须解密哈希值才能开始破解它们。 With the PHP and the database on separate hardware, this becomes much more secure. 将PHP和数据库放在不同的硬件上,这会变得更加安全。

In this article, the link to https://github.com/defuse/php-encryption is shared... 在本文中,共享https://github.com/defuse/php-encryption的链接...

So far, I only used password_hash() in order to store passwords in a database. 到目前为止,我只使用password_hash()来将密码存储在数据库中。 Is it recommendable to encrypt the hash itself? 是否可以加密哈希本身? What's your opinion? 你怎么看?

Thanks for your ideas! 谢谢你的想法!

Hashing with an appropriate hash algorithm is usually enough to protect the passwords, but it is indeed more secure to encrypt (not encode) the hashes afterwards. 使用适当的哈希算法进行散列通常足以保护密码,但事后加密(不编码)哈希确实更安全。

When you encrypt the hashes with a server-side key, an attacker must gain additional privileges on the server , to get this key (without the key, the hashes are worthless). 当您使用服务器端密钥加密哈希时,攻击者必须获得服务器上的其他权限才能获得此密钥(没有密钥,哈希值得无效)。 It is much easier to get readonly access to a database, than to get privileges on a server. 获取对数据库的只读访问要比获取服务器权限容易得多。 Examples are SQL-injection, thrown away backups, discarded servers, ... In all this cases the encryption would protect the hashes. 示例是SQL注入,丢弃备份,丢弃的服务器,......在所有这些情况下,加密将保护哈希。

In this answer you can find more information, or maybe you want to have a look at the end of my tutorial about safely storing passwords. 在这个答案中,您可以找到更多信息,或者您想查看我的教程结尾有关安全存储密码的信息。

Is it recommendable to encode the hash itself? 是否可以对哈希本身进行编码? What's your opinion? 你怎么看?

No, password_hash() / password_verify() is sufficient. 不, password_hash() / password_verify()就足够了。 People who need spinal-tap grade security can refer to that part of the article for guidance to avoid accidentally shooting themselves in the foot trying to improve their security , but in general if you're using bcrypt in 2016 then you're fine . 需要脊柱级别安全性的人可以参考文章的这一部分以获得指导,以避免在脚中意外射击以提高他们的安全性 ,但总的来说,如果你在2016年使用bcrypt,那么你很好

Unless you have separate servers for your website and for your database, the security gain by this strategy is zero. 除非您的网站和数据库具有单独的服务器,否则此策略的安全性增益为零。 If I can get into your database, I can almost certainly get to your file system, and recover the encryption key. 如果我可以进入您的数据库,我几乎可以肯定到达您的文件系统,并恢复加密密钥。

If you do have separate hardware, and you use an authenticated encryption library such as the one provided by Defuse Security, do feel free to use it. 如果您有单独的硬件,并且使用经过身份验证的加密库(例如Defuse Security提供的加密库),请随意使用它。 Just know that it's not necessary for most use cases, as the password hashing API provides decent security against modern password cracking. 只知道大多数用例都没有必要,因为密码散列API提供了对现代密码破解的良好安全性。

In a later version on PHP, they'll also support Argon2. 在PHP的更高版本中,它们也将支持Argon2。 If you're going to go overboard, switch to that instead of adding complexity to your protocol. 如果您要过火,请切换到该协议,而不是为协议增加复杂性。

(Also, it's encrypt, not encode .) (另外,它是加密的,而不是编码 。)

there's no need at all to encrypt the hashes. 根本不需要加密哈希值。 The attacker has to reverse the hash to find the correct plaintext (user password). 攻击者必须反转哈希才能找到正确的明文(用户密码)。 This is equivalent to find out the right key for the encryption. 这相当于找到加密的正确密钥。 hashing is enough. 哈希就足够了。 plus salt obviously otherwise your schema is susceptible to rainbow table attacks 加盐显然否则你的架构容易受到彩虹表攻击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM