I achieved this using the code I found at http://www.a2zmenu.com/Blogs/CSharp/How-to-encrypt-configuration-file.aspx
I would embed my code, but basically it is almost identical to the code on this web page, except for changing application names.
Edit: for a custom section, I'm not sure, since I didn't need to use it, but you could examine what the configuration object gives in the next line.
Configuration config = ConfigurationManager.OpenExeConfiguration(GetAppPath() + "MyAppName.exe");
Here is my entire UpdateKey () method, which I now understand is a bit adapted from the web page. Perhaps this helps.
public static void UpdateKey(string key, string newValue) { Configuration config = ConfigurationManager.OpenExeConfiguration(GetAppPath() + "MyAppName.exe"); config.AppSettings.Settings[key].Value = newValue; config.Save(); }
Then, after I saved my key (s), I call
EncryptAppSettings("appSettings");
and perhaps you can also adapt the parameter value to fit that.
S. Baggy
source share