简体   繁体   English

如何加密和保存密码

[英]How to encrypt and save a password

I am working on the security issue in .net application and I have been reported that My code is vulnerable and I see the issue is the way I store the password 我正在研究.net应用程序中的安全性问题,并且据报告我的代码易受攻击,并且我看到此问题是存储密码的方式

For example: 例如:

<add key="RegxxxChannelPassword" value="test"/>
<add key="xxxRegistrationConnStr" value="xxxxxxxxxx;

So my tool was showing that storing the password in plain text is dangerous . 所以我的工具表明,以纯文本格式存储密码是危险的。

So can I encrpt the password and save it? 那么我可以输入密码并保存吗?

Can some one please suggest me if there are any algorithms? 有人可以请我提出建议吗?

It'd be much more simple to use a membership provider. 使用会员资格提供者会简单得多。 If you're doing the encryption on your own you're reinventing the wheel and disregarding what the framework could do for you. 如果您自己进行加密,那么您就在重新发明轮子,而无视框架可以为您做些什么。

I suggest you go read about it . 我建议你去读一下

The relevant property of the provider, in this case, is passwordFormat . 在这种情况下,提供者的相关属性是passwordFormat

Edit: for a moment there I thought you were talking about user passwords. 编辑:有一会儿我以为你在谈论用户密码。 If it's a password for a connection string, it should be in a .config file, like web.config. 如果它是连接字符串的密码,则应位于.config文件中,例如web.config。 If you have it in the proper place, VS won't complain about it being unencrypted, since it's content that will never get served to a client anyway. 如果您把它放在适当的位置,VS不会抱怨它没有被加密,因为它的内容无论如何也永远不会提供给客户。

You can encrypt sections of the web.config using aspnet_regiis, but the web.config is a pretty standard place to store passwords and such, as long as the website is deployed to a server that you own. 您可以使用aspnet_regiis加密web.config的各个部分,但是只要将网站部署到您拥有的服务器上,web.config都是存储密码等的相当标准的位置。 You could also put the values in the registry, but in most cases, that's unnecessary. 您也可以将值放在注册表中,但是在大多数情况下,这是不必要的。 Here's an article on encrypting web.config sections: 这是有关加密web.config部分的文章:

http://msdn.microsoft.com/en-us/library/zhhddkxy%28v=vs.100%29.aspx http://msdn.microsoft.com/zh-cn/library/zhhddkxy%28v=vs.100%29.aspx

If you go that route, you'll run the command to encrypt the web.config as a deployment step, and the application will handle decrypting and using the values on its own. 如果走那条路,您将运行命令以加密web.config作为部署步骤,应用程序将自行处理解密和使用值。

I'd recommend that you have a look that Rijndael for two-way encryption, if you want to store your password in Web.config: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndael.aspx 如果您希望将密码存储在Web.config中,建议您使用Rijndael进行双向加密: http : //msdn.microsoft.com/zh-cn/library/system.security.cryptography .rijndael.aspx

I agree with @Renan, the proper way to go, is to use MembershipProvider. 我同意@Renan,正确的做法是使用MembershipProvider。

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

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