开发者

Write an application to Encrypt/ decrypt various web.config (vb.net)

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_Lo开发者_开发百科ad(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


Microsoft has a built in way to already encrypt parts of your web.config. There's no need to re-invent the wheel.

If you wanted to build an admin interface to see those settings, then that's easy too. Since it decrypts it in memory (when it's being processed), you can get the relevant sections and dump them into an admin interface. Be advised that any actual change to the web.config will cause an AppPool recycle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜