-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_Program.cs
46 lines (40 loc) · 1.65 KB
/
_Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#region Apache 2 License
// Copyright (c) Applied Duality, Inc., All rights reserved.
// See License.txt in the project root for license information.
#endregion
using System.Configuration;
namespace Playground
{
partial class Program
{
//http://www.a2zmenu.com/Blogs/CSharp/How-to-encrypt-configuration-file.aspx
//http://msdn.microsoft.com/en-us/library/system.configuration.protectedconfigurationprovider.aspx
private static void ProtectConfiguration()
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var provider = "RsaProtectedConfigurationProvider";
var appSettings = config.AppSettings;
if (appSettings != null
&& !appSettings.SectionInformation.IsProtected
&& !appSettings.ElementInformation.IsLocked)
{
appSettings.SectionInformation.ProtectSection(provider);
appSettings.SectionInformation.ForceSave = true;
config.Save();
}
}
private static void UnProtectConfiguration()
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var appSettings = config.AppSettings;
if (appSettings != null
&& appSettings.SectionInformation.IsProtected
&& !appSettings.ElementInformation.IsLocked)
{
appSettings.SectionInformation.UnprotectSection();
appSettings.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
}