当您确实需要在数据库中存储密码时,最佳实践是什么

发布于 2024-10-08 08:40:00 字数 324 浏览 0 评论 0原文

我有一个使用 HMAC 来验证签名请求的 Web 服务。在这种情况下,我的服务的每个调用者都会分配一个密钥(密码)。用户当然会获得该密钥,但我还需要将密钥存储在数据库中,以便我的服务可以验证每个传入请求的签名。

因此,在这种情况下,我确实需要将密码存储在数据库中我可以检索和使用它们的表格。我无法使用仅在数据库中存储密码的加盐哈希的最佳实践。

我可以加密密钥,但随后我需要将加密密钥存储在某处。对于安全的 RESTful Web 服务来说,这是相当常见的场景,因此 Amazon (AWS) 和 Microsoft (Azure) 等公司必须处理这个问题。

这种情况下的最佳做法是什么?

I have a web service using HMAC to verify signed requests. In this scenario there is a key (password) assigned to each caller of my service. The user of course gets that key, but I also need to store the key in my database so that my service can verify the signature of each request coming in.

So this is a case where I really do need to store passwords in the database in a form that I can retrieve and use them. I can't use the best practice of only storing a salted hash of the password in the database.

I could encrypt the keys but then I need to store the encryption key somewhere. This is a fairly common scenario for secured RESTful web services, so the likes of Amazon (AWS) and Microsoft (Azure) have to deal with this problem.

What are best practices in this situation?

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

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

发布评论

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

评论(3

嗳卜坏 2024-10-15 08:40:00

只有当需要密码连接到某些其他系统时,密码才应存储在数据库中。如果仅需要检查其他实体提供的凭据,则应存储密码的哈希值。

即使需要使用密码来与另一方连接,如果您需要一些其他凭据来执行此类访问(例如,某人登录到您的系统,然后您代表他们登录到另一个系统),那么在实际情况下最好存储使用所提供密码的哈希值加密的外部密码(但与数据库中存储的哈希值不同!)。如果有多个可用于登录服务器的凭据,请存储远程密码的加密密钥的单独副本,并使用每个可接受的凭据进行加密。

The only time password should be stored in a database is if the password is needed to connect to some other system. If one merely needs to check the credentials supplied by some other entity, one should store a hash of the password.

Even if it's necessary to use a password to connect with another party, if some other credentials are needed for you to perform such access (e.g. someone logs into your system, and then you log into another system on their behalf) it's desirable when practical to store the external password encrypted with a hash of the supplied password (but NOT the same hash as the one stored in the database!). If there are multiple credentials which could be used to log into your server, store a separate copy of the encryption key for the remote password, encrypted using each acceptable credential.

壹場煙雨 2024-10-15 08:40:00

如果您确实需要密码(例如,为了连接到另一个系统),我建议将其放在远离其他信息的地方。也许是另一个数据库、文件系统上的加密文件等。因此,如果有人获取了您的主数据库,则不能保证他们也获取了相关密码。

这可能是显而易见的,但您希望使用另一个密钥对密码的位置进行加密(以减少以某种方式获得对主数据源的访问权限的人也获得对密码数据存储的访问权限)。

If you really need the password (in order to connect to another system, for example), I would recommend putting in somewhere far away from the other information. Perhaps another database, an encrypted file on the file system, etc. This is so if someone gets your main database, they are not guaranteed to also get the passwords in question.

It may be obvious but you want the location of the passwords to be encrypted with another key (to make it less likely that someone who somehow gained access to the primary data source will also gain access to the password data store).

夜灵血窟げ 2024-10-15 08:40:00

听起来您的场景的最佳实践是使用公钥加密

It sounds like the best practice for your scenario would be to use public key cryptography.

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