加密已经散列的 BCrypt 密码是不是有点过头了?

Is it overkill to encrypt an already hashed BCrypt password?

我正在使用 BCrypt 在服务器端散列我的密码。在我将它存储在我的 MySQL 数据库之前,加密我的散列 BCrypt 密码是否有点过分,或者将散列直接存储在数据库中就足够了吗?

website 建议在对密码进行散列处理后对其进行加密:

As long as an attacker can use a hash to check whether a password guess is right or wrong, they can run a dictionary or brute-force attack on the hash. The next step is to add a secret key to the hash so that only someone who knows the key can use the hash to validate a password. This can be accomplished two ways. Either the hash can be encrypted using a cipher like AES, or the secret key can be included in the hash using a keyed hash algorithm like HMAC.

编辑:我在 Java 中编码。我正在尝试衡量增加的保护层与读取和检索用户登录密码的速度性能是否值得。

这确实会提高安全性,但最好知道加密能带来什么好处。

  • 加密密码哈希可以保护弱用户密码免受攻击 字典攻击,在特殊情况下,攻击者有 对数据库(包含哈希)的读取访问权限,但没有 使用 key/pepper.
  • 访问源代码

这种情况并不像人们想象的那么罕见,典型的情况是SQL-注入、丢弃备份、丢弃服务器...

为了能够暴力破解密码,需要服务器端密钥,该密钥用于加密密码哈希。这意味着,能够从数据库中读取哈希已经不够了,需要额外的权限才能从服务器读取密钥。在服务器上获得权限比能够读取数据库要困难得多。

Crackstation 是一个很好的咨询网站。在我自己关于 safely storing password 的教程的最后,我尝试解释这种密码哈希加密的细节。