Could somebody please do a rundown of how to programmatically encrypt a config-file in .NET, preferably in C#.
What I would like to do is do some kind of check on an application's startup to see if a section is unprotected, and if it is, then encrypt it. This for both settings and connection-strings.
Also if anyone could list the types of encryption-providers and what is the difference between them.
I don't know if the code for doing this in a normal WinForms-application is transparent to doing this in ASP.NET.
The .NET Framework 2.0 allows you to encrypt most configuration sections within the Web.config or machine.config files. The System.Web.Configuration namespace is used to encrypt configuration files via code.
The code, as we will see shortly, simply needs to programmatically reference the appropriate configuration section, call its ProtectSection or UnprotectSection method, and then call the Save method to persist the changes. Moreover, the .NET Framework includes a helpful command line utility that can encrypt and decrypt configuration information.
The aspnet_regiis will only encrypt configuration sections - so you need to selectively encrypt those parts you need, like this: cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 aspnet_regiis.exe -pef "system.serviceModel/bindings" . aspnet_regiis.exe -pef "system.serviceModel/services" .
While a user will have a hard time dealing with encrypted data, ASP.NET has no problems. You can use both of these providers in ASP.NET code. The .NET Framework 2.0 allows you to encrypt most configuration sections within the Web.config or machine.config files. The System.Web.Configuration namespace is used to encrypt configuration files via code.
To summarize the answers and what I've found so far, here are some good links to answer this question:
Please feel free to complement with other links, maybe some to WinForms- or WPF-applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With