我在web.config中有以下条目,我正在使用.NET 2.0和C#进行编码.
@H_502_2@<add key="userName" value="s752549"/>
<add key="userPassword" value="Delhi@007"/>
现在我想要加密,以免身体看到它,这些密码也可能会频繁变化(15天).
解决方法
您可以将用户名和密码放入一个单独的部分,仅对该部分进行加密.例如:
@H_502_2@<?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
@H_502_2@For Ex: aspnet_regiis -pef secureAppSettings . -prov DataProtectionConfigurationProvider