using System.Configuration; using System.Web; using System.Web.Configuration; namespace TicketCenter_DynamicData { public class Encrypt { public static void EncryptConnectionString() { Configuration myConfigurationFile = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath); ConfigurationSection myConnectionStrings = myConfigurationFile.GetSection("connectionStrings"); //ConnectionStringsSection myConnectionStrings = (ConnectionStringsSection)myConfigurationFile.GetSection("connectionStrings"); // Toggle encryption. if (myConnectionStrings != null) { if (myConnectionStrings.SectionInformation.IsProtected) { myConnectionStrings.SectionInformation.UnprotectSection(); } else { myConnectionStrings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); //RsaProtectedConfigurationProvider //DataProtectionConfigurationProvider } myConfigurationFile.Save(); } } } }