存储可解密密码的安全方法

发布于 2024-08-27 10:50:57 字数 244 浏览 5 评论 0原文

我正在用 PHP 制作一个应用程序,并且要求必须能够解密密码,以避免将来将用户数据库切换到不同系统时出现问题。考虑到不可能修改这个未来系统的密码方法,并且我需要纯文本密码才能生成密码。

该计划是使用存储在服务器上的公钥来加密用户的密码。身份验证是通过加密输入并比较结果来完成的。没有完成解密。能够解密的私钥存储在异地供以后使用。

您建议使用什么加密/解密算法?当您认为攻击者无法获得私钥时,加密的密码是否仍与散列(MD5/SHA1)一样安全?

I'm making an application in PHP and there is a requirement that it must be possible to decrypt the passwords in order to avoid problems in the future with switching user database to different system. Consider that it's not possible to modify this future system's password method and I need plain text passwords in order to have the passwords generated.

The plan is to encrypt the user's password with a public key that is stored on the server. Authentication is done by encrypting the input and comparing the results. There is NO decryption done. The private key capable of the decryption is stored off-site for later usage.

What encryption/decryption algorithm would you suggest? Are the encrypted passwords still as safe as hashing (MD5/SHA1) when you consider the private key is not available to the attacker?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

时光是把杀猪刀 2024-09-03 10:50:57

我将重新表述 Jammer 的方法 -

  1. 生成公钥/私钥对。在您的网络服务器上对公钥进行硬编码。将私钥存储在物理银行储物柜中,远离网络服务器/数据库/任何开发人员。
  2. 用户注册时,使用公钥对密码+盐进行加密。此步骤与使用哈希算法相同。将加密后的密码+盐存储在数据库中。
  3. 当您想要验证密码时,请再次加密它,并将其与数据库中存储的值进行比较。

如果攻击者获得了数据库,他无法解密密码,因为他没有私钥。他无法获得私钥,因为私钥位于他无法触及的银行金库中。由于盐的原因,两个相同的密码仍然会以不同的方式存储在数据库中。

我不建议使用上述方法,因为将来任何时候有人都可能滥用私钥并访问所有密码。

但如果你保证私钥始终保持私密,那么我不认为存在技术缺陷。

当然,我可能是错的。

I'll rephrase Jammer's approach -

  1. Generate a public/private key pair. Hard-code the public key on your webserver. Store the private key in a physical bank locker, outside the reach of webserver/database/any developer.
  2. When user registers, encrypt password + salt using public key. This step is identical to using a hash algorithm. Store the encrypted password + salt in the database.
  3. When you want to verify the password, encrypt it again, and compare it to the value stored in the database.

If an attacker gets the database, he can't decrypt the passwords because he doesn't have the private key. He cannot get the private key because it is in a bank vault outside his reach. Two identical passwords will still be stored differently in the database because of the salt.

I don't recommend using the above approach because at any point of time in the future someone could abuse the private key and get access to all passwords.

But if you guarantee that the private key will always remain private, then I don't see a technical flaw.

I could be wrong, of course.

夜唯美灬不弃 2024-09-03 10:50:57

不要解密密码。如果您将来需要更改密码系统,请添加一个名为 storage_type (或其他)的字段。

然后,当您需要更改密码时,您将检查它是否是旧密码。如果是,下次登录时,您可以更改密码编码。否则,请使用新系统登录。

Don't decrypt the password. If you need to change the password system in the future, add a field called storage_type (or whatever).

Then, when you need to change the passwords, you will check if it's an old password. If it is, next time they login, you can change the password encoding. Otherwise, login with the new system.

心在旅行 2024-09-03 10:50:57

能够解密密码是一个坏主意(并且可能没有任何方法比未加密地存储它们更好)。听起来您的主要问题是如果您更改存储方法,则无法使用密码。就像 Linux 所做的那样,存储你如何用密码对密码进行哈希处理。例如 $1$salt$hash 就是 MD5。这样,如果您决定更改密码的存储方式,您仍然可以检查旧密码(如果有人正确登录,您可以使用新的哈希值更新他们的密码)。

Being able to decrypt the passwords is a bad idea (and there's probably not any way of doing it that would be much better than storing them unencrypted). It sounds like your main problem is being able to use the passwords if you change your storage method. Just do what Linux does, store how you're hashing the password with the password. So for example $1$salt$hash is MD5. That way, if you decide to change how passwords are stored, you can still check against the old passwords (and if someone logs in correctly, you can update their password with the new hash).

A君 2024-09-03 10:50:57

我看到的唯一问题是,大多数公私密钥加密代码将使用公钥加密对称密钥,并依赖私钥解密,然后使用对称密钥加密消息。

你想用公钥直接加密密码+盐。

因此,针对您的系统的攻击可以归结为:

  1. 针对通用公钥/私钥加密的攻击
  2. 针对您的私钥存储的攻击。

The only problem I see is that most public-private key encryption code out there will encrypt a symmetric key using the public key, and rely on the private key decrypting that, then use the symmetric key to encrypt the message.

You want to use the public key to directly encrypt the password+salt.

So attacks against your system boil down to:

  1. Attacks against general public/private key encryption
  2. Attacks against your private key store.
|煩躁 2024-09-03 10:50:57

对于大多数应用程序来说,存储密码的 SHA-1 哈希值就足够了。

是的,大多数哈希算法中都存在已知的冲突,但这并不意味着实际的攻击向量。尤其是当你对哈希值加盐时。

对于您的 salt:将其存储在一个配置文件中,该文件无法从外部访问,但可以由您的 PHP 安装读取。

For most applications it is more than sufficient to store SHA-1 hashes of passwords.

Yes, there are known collisions in most hashing algorithms, but that doesn't imply an actual attack vector. Especially when you're salting the hashes.

For your salt: Store it in a configuration file that is not accessible from the outside but can be read by your PHP installation.

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