<connectionString value="Data Source=HEMTECH\SA;Initial Catalog=HemWizard;User ID=sa; Password=hemtech;" />
<add key="DBConnString" value="RGF0YSBTb3VyY2U9SEVNVEVDSFxTQTtJbml0aWFsIENhdGFsb2c9SGVtV2l6YXJkO1VzZXIgSUQ9c2E7IFBhc3N3b3JkPWhlbXRlY2g7"/>
public static void EncryptConnectionString(bool encrypt, string fileName) { Configuration configuration = null; try { // Open the configuration file and retrieve the connectionStrings section. configuration = ConfigurationManager.OpenExeConfiguration(fileName); ConnectionStringsSection configSection = configuration.GetSection("connectionStrings") as ConnectionStringsSection; if ((!(configSection.ElementInformation.IsLocked)) && (!(configSection.SectionInformation.IsLocked))) { if (encrypt && !configSection.SectionInformation.IsProtected) { //this line will encrypt the file configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); } if (!encrypt && configSection.SectionInformation.IsProtected)//encrypt is true so encrypt { //this line will decrypt the file. configSection.SectionInformation.UnprotectSection(); } //re-save the configuration file section configSection.SectionInformation.ForceSave = true; // Save the current configuration configuration.Save(); Process.Start("notepad.exe", configuration.FilePath); //configFile.FilePath } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)