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();
}
}
}
{
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();
}
}
}
No comments:
Post a Comment