2011-02-25 85 views
0

我想寫一個應用程序,將加密和解密已被選中的web.config。編寫一個應用程序加密/解密各種web.config(vb.net)

我已經找到了一些代碼,像這樣的應用程序中做到這一點...

進口系統 進口System.Configuration 進口System.Web.Configuration

保護小組的Page_Load(BYVAL發件人爲對象,BYVALË作爲System.EventArgs)把手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 

什麼我想要做的是把這個勝利窗體應用程序有幾個按鈕(btnEncrypt和btndecrypt的)和瀏覽控制(瀏覽到各種web.configs)。

應用程序可以被我們的OPS人使用,使他們能夠加密或解密在我們所有的Web應用程序的所有web.configs,而無需重新發布等...

任何幫助將不勝感激。

謝謝

+0

或者使用這一切都已爲您完成:http://somewebguy.wordpress.com/2009/07/16/encrypt-your-web-config-please/ – PhilPursglove 2011-02-25 11:55:16

+0

謝謝我會看看在那家 - 即時在工作中被阻止從該網站! – Anna 2011-02-25 12:14:48

回答

3

微軟has a built in way to already encrypt parts of your web.config。沒有必要重新發明輪子。

如果您想構建一個管理界面來查看這些設置,那麼這也很簡單。由於它在內存中進行解密(處理時),您可以獲取相關部分並將其轉儲到管理界面中。請注意,對web.config的任何實際更改都會導致AppPool回收。

+0

事情是我想加密身份模仿,以便公司內的人不能看到用戶名和密碼 - 除了可能不得不更改某些密碼等的操作... – Anna 2011-02-25 14:39:38

+0

我很新,這個我很害怕 - 他們不是一個製作應用程序的方法嗎? – Anna 2011-02-25 14:40:25

+0

@Anna對web.config的那一部分進行加密要容易得多。如果「Ops」能夠看到它,那麼就建立一個僅暴露於「操作」規則的管理界面,以便他們可以看到它是什麼。 – 2011-02-25 14:47:41