避免設定檔中連線字串部分以明碼顯示
path = Process.GetCurrentProcess().MainModule.FileName;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void EncryptConnString(string path) | |
{ | |
Configuration config = ConfigurationManager.OpenExeConfiguration(path); | |
ConfigurationSection section = config.GetSection("connectionStrings"); | |
if (!section.SectionInformation.IsProtected) | |
{ | |
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider"); | |
config.Save(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Decrypt method | |
public static void DecryptConnString(string path) | |
{ | |
Configuration config = ConfigurationManager.OpenExeConfiguration(path); | |
ConfigurationSection section = config.GetSection("connectionStrings"); | |
if (section.SectionInformation.IsProtected) | |
{ | |
section.SectionInformation.UnprotectSection(); | |
config.Save(); | |
} | |
} | |
#endregion |
沒有留言:
張貼留言