简体   繁体   English

如何保护存储在数据库中的敏感密码

[英]How to Protect Sensible Passwords stored in a Database

I'm developing a web application for which final users have to create an account. 我正在开发一个Web应用程序,最终用户必须为其创建一个帐户。 This part is very easy: I'll hash their passwords with SHA-256 so that nobody, except the user himself, knows the password. 这部分非常简单:我将使用SHA-256对密码进行哈希处理,以便除了用户自己以外没有人知道密码。 Now comes the difficult part. 现在来了困难的部分。 After the user creates an account, he/she has to provide the password of his/her email server. 用户创建帐户后,他/她必须提供他/她的电子邮件服务器的密码。 Now the question is: how can I protect this password decently (the password will be stored in a database)? 现在的问题是:我如何正确地保护这个密码(密码将存储在数据库中)? If I encrypt the password with TripleDES, any developer or system administrator would be able to decrypt the password and see it. 如果我使用TripleDES加密密码,任何开发人员或系统管理员都可以解密密码并查看密码。 What is the usual way to deal with such a problem? 处理这种问题的常用方法是什么? Many Thanks. 非常感谢。

The usual way to do this is to use an symmetric encryption key which is derived from the user's password. 通常的方法是使用从用户密码派生的对称加密密钥。 The standard way to do this is using the algorithm specified in RFC2898 , which generates a set of cryptographically secure bytes you can use as a key and IV. 执行此操作的标准方法是使用RFC2898中指定的算法,该算法生成一组可用作密钥和IV的加密安全字节。 It's probably supported by a library for your language, .NET for example, which is what I use has the Rfc2898DeriveBytes class. 它可能是由您的语言库支持的,例如.NET,我使用的是Rfc2898DeriveBytes类。

Of course when your user changes their password you will have to decrypt any existing cipher text and then derive the new key and re-encrypt. 当然,当您的用户更改其密码时,您必须解密任何现有的密码文本,然后派生新密钥并重新加密。

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

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