我使用 RSA 容器密钥加密来加密 web.config 中的 appSettings。在 IIS Express 中运行时,加密的 Web 配置在 Visual Studio 中运行良好。但是当我在项目属性中将其更改为本地 IIS(在 VS 2015 中)时,我收到了错误
"Failed to decrypt using provider 'MyEncryptionProvider'. Error message from the provider: The RSA key container could not be opened.".
如果 web 配置被解密,它可以在本地 IIS 和 IIS Express 中工作。
这些是我使用的命令:
aspnet_regiis.exe -pc MyCustomKeys -exp
aspnet_regiis.exe -pa MyCustomKeys "NT AUTHORITY\NETWORK SERVICE"
aspnet_regiis.exe -pef appSettings "D:\Demo\Encrypting configuration" -prov MyEncryptionProvider
configProtectedData
<configProtectedData>
<providers>
<add keyContainerName="MyCustomKeys"
useMachineContainer="true"
name="MyEncryptionProvider"
type="System.Configuration.RsaProtectedConfigurationProvider"/>
</providers>