我需要为 ASP.Net 4.0 项目加密部分 web.config,但我们需要使用 AES,默认值似乎是 Triple DES。我如何告诉它使用 AES 加密?
在命令提示符中,我执行以下命令:
aspnet_regiis -pc "NetFrameworkConfigurationKey" -exp
aspnet_regiis -pe "connectionStrings" -app "/<myapp>"
我想我通过选择适当的 CSP (-csp) 将加密方法设置为 AES,但我无法找到或弄清楚正确的名称。
加密的 web.config 中的一行是:
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
最佳答案
使用 aspnet_regiis 的 -prov 参数选择提供程序。提供程序使用 configProtectedData 部分在 web/machine.config 中注册。为了注册 AES,您可以使用如下内容:
<configProtectedData>
<providers>
<add name="AesProvider"
type="Microsoft.ApplicationHost.AesProtectedConfigurationProvider"
description="Uses an AES session key to encrypt and decrypt"
keyContainerName="iisConfigurationKey" cspProviderName=""
useOAEP="false" useMachineContainer="true"
sessionKey="aSessionKeyGoesHere" />
</providers>
</configProtectedData>
在我的机器上,RSA和DPAPI是machine.config中预先配置的算法。
如果 AES 提供程序已注册,您应该能够使用以下方法加密配置部分:
aspnet_regiis -pe "connectionStrings" -app "/<myapp>" -prov "AesProvider"
关于asp.net - 如何使用 aspnet_regiis 选择/强制执行 AES 加密来加密 web.config 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776386/