2011-02-08 130 views
4

因此,使用ASPNET_REGIIS.EXE UTIL我做了以下爲什麼在不提供keyContainerName的情況下加密Web.config文件?

//Create the container 
aspnet_regiis -pc MyRSAKey -exp 

//Write key to file 
aspnet_regiis -px MyRSAKey MyRSAKey.xml 

//Install the key into a machine-level RSA key provider. 
aspnet_regiis -pi MyRSAKey MyRSAKey.xml 

//Grant access to the contrainer 
aspnet_regiis -pa "MyRSAKey" "NT Authority\Network service" 

現在我想使用這個關鍵,我需要把它添加到web.config文件

<configProtectedData defaultProvider="MyProviderName"> 
<providers> 
    <add 
    name="MyProviderName" 
    type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"   
    keyContainerName="MyRSAKey" 
    useMachineContainer="true" /> 
</providers> 

現在,當我運行此命令時,它的工作原理:

aspnet_regiis -pef "sectiomName" "pathToConfigFile" -prov "MyProviderName" 

問題是,無論keyContainerName具有什麼樣的值,它都能正常工作。或者甚至當我將keyContainerName從配置文件中完全取出時,它仍然有效,表明它實際上並未使用我生成並安裝的密鑰。

另外visual studio 2010甚至不認識keyContainerName(或useMachineContainer),說'keyContainerName'的名字是不允許的。

這是怎麼回事?

+0

爲什麼使用[多個感嘆號](http://wiki.lspace.org/wiki/Multiple_exclamation_marks)? – 2011-02-08 15:24:14

回答

0

爲了解決這兩個問題不按順序:

Visual Studio 2010中甚至不承認keyContainerName(或useMachineContainer)說,「keyContainerName的名字是不允許的。

這是怎麼回事?

我沒有反編譯相關的配置部分類進行檢查,但我觀察到RsaProtectedConfigurationProvider具有屬性KeyContainerNameUseMachineContainer,因此它似乎是一個)解析providers/add元件時,它使用反射來設置相應的字段例如type;和b)凡編寫VS2010用於驗證.config文件的XML架構的人員忘記了<xsd:anyAttribute>標記。

(FWIW這個問題是我在發現你的問題時希望回答的問題,這個問題在Google中排名很高,爲keycontainername attribute is not allowed)。


的事情是,它的作品無論我有什麼價值keyContainerName。或者甚至當我將keyContainerName從配置文件中完全取出時,它仍然有效,表明它實際上並未使用我生成並安裝的密鑰。

當你說「有效」時,我認爲你的意思是aspnet_regiis -pef不會給出錯誤。但是,如果您嘗試訪問代碼中的受保護配置部分,我敢打賭它會發出抱怨,除非您使用了正確的keyContainerName

我懷疑如果這個名字不對應一個已知的密鑰容器,它會創建一個新的密鑰容器,但我沒有試圖驗證這一點。

相關問題