There are two blocks which I will paste below. There are two files that were created during the encrypt process. et3eohbx.newcfg and et3eohbx.tmp. et3eohbx.newcfg is an exact copy of web.config with the exception of the cipherdata section it contains.
in loadData()
Code:
if (AppLogic.TrustLevel == AspNetHostingPermissionLevel.Unrestricted)
{
Configuration webconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
AppSettingsSection appsettings = (AppSettingsSection)webconfig.GetSection("appSettings");
rblEncrypt.Items.FindByValue(appsettings.SectionInformation.IsProtected.ToString().ToLowerInvariant()).Selected = true;
}
in btnSubmit_Click
Code:
if (AppLogic.TrustLevel == AspNetHostingPermissionLevel.Unrestricted)
{
string encyptionprovider = AppLogic.AppConfig("Web.Config.EncryptionProvider");
if (encyptionprovider != "DataProtectionConfigurationProvider" && encyptionprovider != "RsaProtectedConfigurationProvider")
{
encyptionprovider = "DataProtectionConfigurationProvider";
}
Configuration webconfig = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
AppSettingsSection appsettings = (AppSettingsSection)webconfig.GetSection("appSettings");
if (rblEncrypt.SelectedValue.Equals("true", StringComparison.InvariantCultureIgnoreCase) &&
!appsettings.SectionInformation.IsProtected)
{
appsettings.SectionInformation.ProtectSection(encyptionprovider);
appsettings.SectionInformation.ForceSave = true;
webconfig.Save(ConfigurationSaveMode.Full);
}
else if (rblEncrypt.SelectedValue.Equals("false", StringComparison.InvariantCultureIgnoreCase) &&
appsettings.SectionInformation.IsProtected)
{
appsettings.SectionInformation.UnprotectSection();
appsettings.SectionInformation.ForceSave = true;
webconfig.Save(ConfigurationSaveMode.Full);
}
}