【问题标题】:How do I select/enforce AES encryption with aspnet_regiis to encrypt web.config values?如何使用 aspnet_regiis 选择/强制执行 AES 加密来加密 web.config 值?
【发布时间】:2012-02-05 06:39:36
【问题描述】:

我需要为我们的 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" />

【问题讨论】:

    标签: asp.net encryption web-config aes aspnet-regiis.exe


    【解决方案1】:

    提供程序是使用 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"
    

    【讨论】:

    • Re: sessionKey="aSessionKeyGoesHere": 这与互联网请求会话有关吗?我将把它设置成什么,或者我将如何计算或得出一个合适的值?
    • 另外,我已经尝试在我的应用程序的 web.config 和 machine.config 中实现这一点,但我总是收到此错误:加密配置部分...无法加载类型'Microsoft.ApplicationHost来自程序集“System.Configuration,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”的.AesProtectedConfigurationProvider'。失败!
    • sessionKey 是要使用的 AES 加密密钥。可能在框架历史的某个时刻,AesProtectedConfigurationProvider 已从可用的加密提供程序中删除,现在只有 RSA 和 DPAPI 是核心的一部分。除了在一些旧的加密示例和 machine.config 示例中引用之外,我一直无法找到 Aes 提供程序的来源。
    猜你喜欢
    • 2012-10-01
    • 2014-05-31
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2012-01-10
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多