I have the following information in my web.config file.
<appSettings>
<add key="AdminUsername" value="User1"/>
<add key="AdminPassword" value="Password1"/>
</appSettings>
how do I encrypt it and store? how do I decrypt and use?
I have the following information in my web.config file.
<appSettings>
<add key="AdminUsername" value="User1"/>
<add key="AdminPassword" value="Password1"/>
</appSettings>
how do I encrypt it and store? how do I decrypt and use?
Kindly refer to the article - http://msdn.microsoft.com/en-us/library/k6h9cz8h%28v=vs.80%29.aspx
The command is:
aspnet_regiis.exe -pe "appSettings" -site "MySharePoint" -app "/"
where MySharePoint is a Virtual Directory. The web.config file should be inside the directory too.
使用 aspnet_regiis 或等效 API 加密配置部分的缺点是它会加密整个部分。
从安全角度来看很好,但它使管理员更难检查同一部分中的其他非敏感配置数据。appSettings 是管理员经常想要检查的部分。
一种选择是将您的凭据放在不同的部分(例如,在该<connectionStrings>
部分中创建一个虚拟连接字符串)并仅加密此部分:
<connectionStrings>
...
<add key="AdminCredentials"
providerName=""
connectionString="Username=...;Password=..." />
</connectionStrings>
您当然必须编写代码来解析虚拟连接字符串 (String.Split) 并提取凭据。类似于以下内容(为简单起见省略错误处理):
string s = ConfigurationManager.ConnectionStrings["AdminCredentials"].ConnectionString;
string[] tokens = s.Split(';');
string userName = tokens[0].Split('=')[1];
string password = tokens[1].Split('=')[1];
...
通过这样做,您可以不加密您的 appSettings 部分。