How to Encrypting/Decrypting web.config Information
By Kalit Sikka
How to Encrypting/Decrypting web.config Information
public class EncryptDecryptWebConfig
{
public static void mEncryptWebConfig(string appPath, string protectedSection, string dataProtectionProvider)
{
System.Configuration.Configuration
webConfig =
WebConfigurationManager.OpenWebConfiguration(appPath);
ConfigurationSection
webConfigSection = webConfig.GetSection(protectedSection);
if (!webConfigSection.SectionInformation.IsProtected)
{
webConfigSection.SectionInformation.ProtectSection(dataProtectionProvider);
webConfig.Save();
}
}
public static void mDecryptWebConfig(string appPath, string protectedSection)
{
System.Configuration.Configuration
webConfig =
WebConfigurationManager.OpenWebConfiguration(appPath);
ConfigurationSection
webConfigSection = webConfig.GetSection(protectedSection);
if (webConfigSection.SectionInformation.IsProtected)
{
webConfigSection.SectionInformation.UnprotectSection();
webConfig.Save();
}
}
}
Popularity (1046 Views)