【问题标题】:Why encrypting Web.config file works without supplying a keyContainerName?为什么在不提供 keyContainerName 的情况下加密 Web.config 文件?
【发布时间】:2011-02-08 15:19:09
【问题描述】:

所以使用 aspnet_regiis.exe 工具我已经完成了以下操作

//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”名称。

这是怎么回事?

【问题讨论】:

标签: .net asp.net web-config web-config-encryption


【解决方案1】:

无序地解决这两个问题:

Visual Studio 2010 甚至无法识别 keyContainerName(或 useMachineContainer)表示不允许使用“keyContainerName”名称。

这是怎么回事?

我还没有反编译相关的配置节类来检查,但我观察到RsaProtectedConfigurationProvider 具有属性KeyContainerNameUseMachineContainer,所以它似乎是a)在解析它使用的providers/add 元素时反射在type的实例上设置相应的字段; b) 编写 VS2010 用来验证 .config 文件的 XML 模式的人忘记了 &lt;xsd:anyAttribute&gt; 标记。

(当我发现你的问题时,这个问题是我希望回答的,因为keycontainername attribute is not allowed 在 Google 中排名很高)。


问题是,无论我对 keyContainerName 有什么价值,它都有效。或者即使我将 keyContainerName 完全从配置文件中取出,它仍然可以工作,这表明它实际上并没有使用我生成和安装的密钥。

当您说“它有效”时,我认为您的意思是 aspnet_regiis -pef 没有给出错误。但是,如果您尝试访问代码中受保护的配置部分,我敢打赌它会抱怨,除非您使用正确的 keyContainerName

我怀疑如果名称与已知的密钥容器不对应,它会创建一个新的,但我没有尝试验证这一点。

【讨论】:

    猜你喜欢
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 2022-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多