I'm trying to write an application that will encrypt and decrypt a web.config which has been selected.
I have found some code to do this within an application like so...
Imports System Imports System.Configuration Imports System.Web.Configuration
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'encrypt/decrypt identity
Dim config As Configuration
Dim configSection As ConfigurationSection
'encrypt identity
config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
If Not (config Is Nothing) Then
configSection = config.GetSection("system.web/identity")
If Not (configSection Is Nothing) Then
If Not (configSection.SectionInformation.IsLocked) Then
configSection.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
config.Save()
End If
End If
End If
'decrypt identity
config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
configSection = config.GetSection("system.web/identity")
If Not (configSection Is Nothing) Then
If Not (configSection.SectionInformation.IsLocked) Then
configSection.SectionInformation.UnprotectSection()
config.Save()
End If
End If
What i wanted to do was put this in a win forms application with a couple of buttons (btnEncrypt and btndecrypt) and a browse control (to browse to the various web.configs).
The application can then be used by our ops guys so they can encrypt or decrypt all the web.configs in all our web applications without having to re-publish etc...
Any help would be much appreciated.
Thanks