No es tan dificil, pero entenderlo requiere de conocimientos medios/avanzados sobre .net
Código
using System; using System.Configuration; using System.Xml; namespace EncryptAppConfigSections.Properties { internal sealed partial class Settings { public Settings() { this.SettingsSaving += this.SettingsSavingEventHandler; } private void SettingsSavingEventHandler(object sender, EventArgs e) { ProtectSection("connectionStrings"); } private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { Console.WriteLine(e.SettingClass.ToString()); Console.WriteLine(e.SettingName.ToString()); ProtectSection("connectionStrings"); } private void ProtectSection(String sSectionName) { Configuration config = ConfigurationManager. OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection section = config.GetSection(sSectionName); if (section != null) { if (!section.IsReadOnly()) { section.SectionInformation.ProtectSection ("RsaProtectedConfigurationProvider"); section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); } } } } }
No hace falta crear un método para "Desproteger" ya que esto es parte del framework y tampoco hace falta crear clases especiales, solamente es esto y ya..
Un saludo!