You can protect any information in the configuration file. This link is for a walkthrough. Encrypting configuration information using a secure configuration explains how
UPDATE: Sorry for the broken link, I update it and add the title of the article. The solution uses RsaProtectedConfigurationProvider . I created a simple method in my helper class WebUtility:
public static void CheckWebConfigSecured(string webPath, params string[] sections) { Configuration confg = WebConfigurationManager.OpenWebConfiguration(webPath); bool done = false; foreach (string section in sections) { ConfigurationSection confSection = confg.GetSection(section); if ((confSection != null) && !confSection.SectionInformation.IsProtected) { confSection.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider"); done = true; } } if (done) { confg.Save(); } }
I am calling from Global.asax.cs in Application_BeginRequest
WebUtility.CheckWebConfigSecured( context.Request.ApplicationPath, "connectionStrings", "appSettings", "log4net");
If connectionStrings, appSettings and log4net are the web.config sections that I want to protect.
As a result, these sections in the Web.config file on the server look as follows, after the first visit to the site after deployment:
<appSettings configProtectionProvider="RsaProtectedConfigurationProvider"> <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#"> <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" /> <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <KeyName>Rsa Key</KeyName> </KeyInfo> <CipherData> <CipherValue>YbjvJF6IpTaEFb58ag1O ... HJm1uzA=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>mzJ2PoteOG7ZpAs922sounmG ... 02D3ZiM1PCliSw==</CipherValue> </CipherData> </EncryptedData> </appSettings>
source share