簡體   English   中英

加密WebConfig

[英]Encrypting WebConfig

我有一個Web應用程序,我使用'publish'選項將其發布到三個Web服務器。

我想加密Web配置文件的connectionstrings部分。 以下命令將執行此操作:

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef "connectionStrings" c:\inetpub\application

但是,我必須將RDP(遠程桌面)連接到每個服務器並在每個服務器上運行命令,因為您無法像這樣(從客戶端PC)運行它:

\\ servername \\ c $ \\ WINDOWS \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ aspnet_regiis.exe -pef“connectionStrings”\\ servername \\ c $ \\ inetpub \\ application

有沒有更好的方法:或許:

1)發布后在服務器上執行命令行2)在Visual Studio中使用構建選項,允許您在發布完成后執行批處理文件

加密服務器上web.config的connectionStrings部分,然后將此加密部分添加到您的網站。[CONFIGURATION_FOR_SERVER] .config轉換文件。 第一行的關鍵是用這個新的加密值替換原始web.config的connectionStrings部分。 您將需要為要發布的每個服務器創建一個新的轉換文件。 Visual Studio將發出警告(而不是錯誤),即

Warning 15  The element 'connectionStrings' has invalid child element 'EncryptedData' in namespace 'http://www.w3.org/2001/04/xmlenc#'. List of possible elements expected: 'add, remove, clear'.   C:\DevTFS\YourProject\Web.Stage.config  14  6   YourProject

關於這個轉換文件的格式 - 我還沒有找到正確的語法來解決這個問題,所以我願意接受建議,但它仍然有效,所以我很高興。 關於此的完整博客文章: http//randomdotnetnuggets.blogspot.com.au/2013/05/publishing-encrypted-connection-strings.html

<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider" xdt:Transform="Replace">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
  xmlns="http://www.w3.org/2001/04/xmlenc#">
  <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
  <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
    <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <KeyName>Rsa Key</KeyName>
      </KeyInfo>
      <CipherData>          
         <CipherValue>t8p7aOZTjMo...zE6FAAI=</CipherValue>
      </CipherData>
    </EncryptedKey>
  </KeyInfo>
  <CipherData>
    <CipherValue>Vy1TZWY8....ic+Qg6T7U</CipherValue>
  </CipherData>
</EncryptedData>

如果不能選擇集成安全性,我建議您使用MS Web Deploy

使用Visual Studio 2012構建部署包時,您將獲得zip文件和命令行腳本文件。 您可以修改該腳本文件以加密web.config或滾動自己的批處理腳本或PowerShell腳本。

這是一個老問題,但這個答案可能對某人有所幫助。

在負載平衡或Web場方案中,您可以加密文件一次並將web.config復制到其他計算機。 但是,為此,您必須為每個網站使用相同的計算機密鑰。

https://msdn.microsoft.com/en-us/library/dtkwfdky.aspx

希望這有助於任何人搜索這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM