如何在Web.config中C#2.0中加密的用户名和密码 [英] How to encrypt username and password in Web.config in C# 2.0
本文介绍了如何在Web.config中C#2.0中加密的用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有低于我的web.config条目和我使用.NET 2.0和C#编码。
I have got below entries in my web.config and I am using .NET 2.0 and C# for coding.
<add key="userName" value="s752549"/>
<add key="userPassword" value="Delhi@007"/>
现在我希望这是加密,使得没有任何机构可以看到它,也是这些密码可能经常改变(在时间15天)。
Now I want this to be encrypted so that no body can see it and also these password may change frequently (in 15days of time).
推荐答案
您可以把用户名和密码到单独的部分,只有加密这个部分。例如:
You could put the username and password into a separate section and encrypt this section only. For example:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="secureAppSettings" type="System.Configuration.NameValueSectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<appSettings>
<add key="Host" value="www.foo.com" />
<add key="Token" value="qwerqwre" />
<add key="AccountId" value="123" />
<add key="DepartmentId" value="456" />
<add key="SessionEmail" value="foo@foo.com" />
<add key="DefaultFolder" value="789" />
</appSettings>
<secureAppSettings>
<add key="userName" value="s752549"/>
<add key="userPassword" value="Delhi@007"/>
</secureAppSettings>
</configuration>
,然后使用aspnet_regiis的
and then use aspnet_regiis
For Ex:
aspnet_regiis -pef secureAppSettings . -prov DataProtectionConfigurationProvider
这篇关于如何在Web.config中C#2.0中加密的用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文