所以使用 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”名称。
这里发生了什么?