ASPNET_REGIIS:将AES密钥和IV放入KeyContainer [英] ASPNET_REGIIS: Place AES key and IV into a KeyContainer

查看:100
本文介绍了ASPNET_REGIIS:将AES密钥和IV放入KeyContainer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用ASPNET_REGIIS将AES密钥和IV放入KeyContainer中?如果是,怎么办?

Is it possible to place an AES key and IV into a KeyContainer using ASPNET_REGIIS? If yes, how?

上下文:

我创建了AesProtectedConfigurationProvider进行加密使用AES而不是Triple DES(即3DES)的web.config数据。我还创建了一个控制台应用程序,该控制台应用程序使用AesProtectedConfigurationProvider来生成AES密钥和初始化向量(IV)。我可以将密钥保存到文本文件,然后在web.config的提供程序中引用该文本文件。从那里,我能够加密web.config文件。但是,如果可能的话,我想通过将它们移到KeyContainer中来保护它们。

I have created AesProtectedConfigurationProvider to encrypt web.config data using AES as opposed to Triple DES (i.e., 3DES). I have also created a console application that uses the AesProtectedConfigurationProvider in order to generate both the AES key and initialization vector (IV). I can save the key to a text file and then reference the text file in the provider of the web.config. From there, I am able to encrypt the web.config file. But, I would like to protect the keys.txt file by moving them into a KeyContainer, if that is possible.

因此,在provider标签下,keyContainerName部分将会是:

So, under the provider tag, the section for keyContainerName would be:

keyContainerName="AesKeyContainer" 

相对于

keyContainerName="C:\AesKey.txt"

我的理解是ASPNET_REGIIS中现成可用的当前加密产品使用3DES加密内容使用RsaProtectedConfigurationProvider加密3DES密钥时的web.config文件的文件名(如果我错了,请更正我)。因此,如果可以使用RsaProtectedConfigurationProvider将AES密钥加密到KeyContainer中,则将很有帮助。我已经审查了以下站点,但不确定是否可行:

My understanding is the current encryption offering that is available out of the box in ASPNET_REGIIS uses 3DES to encrypt the contents of the web.config file while the RsaProtectedConfigurationProvider is used to encrypt the 3DES keys (please correct me if I am wrong on this). So, if it is possible to use the RsaProtectedConfigurationProvider to encrypt the AES keys into a KeyContainer then that would be helpful. I have reviewed the following sites and I am not sure if this is possible:

https://msdn.microsoft.com/zh-CN/library/33ws57y0.aspx

如何使用AES而不是3DES加密web.config

编辑:
有谁知道为什么Microsoft在随后的.NET版本中删除了AesProtectedConfigurationProvider吗?这似乎是倒退了一步,因为AES是当前的标准,而不再建议使用3DES。在与同事交谈时,他们提到它可能是由于安全漏洞而被删除的,例如:特权提升。 Microsoft以在安全方面进行未经通知的更改而闻名。但是,我想知道是否有人肯定。如果确实在AesProtectedConfigurationProvider中发现了缺陷,那么我可能会倾向于使用3DES。

Does anyone know why Microsoft took out the AesProtectedConfigurationProvider in subsequent releases of .NET? This seems like a step backwards as AES is the current standard while 3DES is no longer recommended. In speaking with a colleague, they mentioned that it may have been removed due to a security flaw, such as; elevation of privileges. Microsoft is known for making unannounced changes with respect to security. But, I would like to know if anyone knows for sure. If, indeed, a flaw was found in the AesProtectedConfigurationProvider, then I might be inclined to stay with 3DES.

推荐答案

RsaProtectedConfigurationProvider AesProtectedConfigurationProvider 尽管名称非常相似,但却是不同Universe的一部分。

RsaProtectedConfigurationProvider and AesProtectedConfigurationProvider, despite very similar names, are parts of different universes.

RsaProtectedConfigurationProvider 驻留在<$ c中$ c> System.Configuration 并用于(与从抽象 ProtectedConfigurationProvider 继承的其他提供程序一样)对web.config中的配置节进行加密/解密ASP.NET应用程序。

RsaProtectedConfigurationProvider resides in System.Configuration and is used (as other providers inheriting from abstract ProtectedConfigurationProvider) for encryption/decryption of configuration sections in web.config for ASP.NET applications.

AesProtectedConfigurationProvider 依次位于 Microsoft.ApplicationHost ,仅用于IIS配置加密。在默认应用程序池的配置文件(DefaultAppPool.config)中,您将找到以下内容:

AesProtectedConfigurationProvider in its turn resides in Microsoft.ApplicationHost and is used only for IIS configuration encryption. In configuration file of default application pool (DefaultAppPool.config) you will find following:

<configProtectedData>
    <providers>
        <!-- ... -->
        <add name="AesProvider" type="Microsoft.ApplicationHost.AesProtectedConfigurationProvider" ... />
        <add name="IISWASOnlyAesProvider" type="Microsoft.ApplicationHost.AesProtectedConfigurationProvider" ... />
    </providers>
</configProtectedData>

您可以阅读有关 AesProvider 和<$ IIS安全配置 IISWASOnlyAesProvider >文章:

You could read about AesProvider and IISWASOnlyAesProvider in IIS Securing Configuration article:


AesProvider-IIS工作进程使用AES加密对IIS配置节进行加密。

AesProvider - Encrypting IIS configuration sections read by the IIS worker process using AES encryption.

IISWASOnlyAesProvider-使用AES加密对WAS读取的IIS配置节进行加密。

IISWASOnlyAesProvider - Encrypting IIS configuration sections read by WAS using AES encryption.

所以回答第一个问题:



  1. 确认使用AesProtectedConfigurationProvider是否安全。微软在随后的.NET版本中将其删除,但我
    似乎找不到原因


是的,如果我们假设您正确实施了自定义AES提供程序而没有安全漏洞,则使用它是安全的。 Microsoft尚未从.Net Framework中删除 AesProtectedConfigurationProvider ,它从未成为 System.Configuration 的一部分。如果Microsoft在实施中发现了安全漏洞,他们可以修复它而不是删除它,对吗?

Yes, using of your custom AES provider is safe if we assume that you have implemented it correctly without security flaws. Microsoft has not removed AesProtectedConfigurationProvider from .Net Framework, it was never a part of System.Configuration. If Microsoft has found security flaw in its implementation, they could just fix it instead of removing, correct?



  1. 提供步骤以实现AesProtectedConfigurationProvider并在ASPNET_REGIIS中创建KeyContainer


I相信您可以在不实现自定义 AesProtectedConfigurationProvider 的情况下进行AES加密。

I believe you can have AES encryption without implementing custom AesProtectedConfigurationProvider.

我深入研究 RsaProtectedConfigurationProvider c>,并发现它具有以下逻辑:

I dig into source code of RsaProtectedConfigurationProvider and found that it has the following logic:

private SymmetricAlgorithm GetSymAlgorithmProvider() {
    SymmetricAlgorithm symAlg;

    if (UseFIPS) {
        // AesCryptoServiceProvider implementation is FIPS certified
        symAlg = new AesCryptoServiceProvider();
    }
    else {
        // Use the 3DES. FIPS obsolated 3DES
        symAlg = new TripleDESCryptoServiceProvider();

        byte[] rgbKey1 = GetRandomKey();
        symAlg.Key = rgbKey1;
        symAlg.Mode = CipherMode.ECB;
        symAlg.Padding = PaddingMode.PKCS7;
    }

    return symAlg;
}

如您所见,默认 RSAProtectedConfigurationProvider 通过 System.Security.Cryptography.AesCryptoServiceProvider 支持从三重DES加密切换到AES加密。

As you see, default RSAProtectedConfigurationProvider supports switch from Triple DES to AES encryption by means of System.Security.Cryptography.AesCryptoServiceProvider.

RsaProtectedConfigurationProvider 的配置部分读取 UseFIPS 标志。您可以在计算机级别(machine.config)上进行设置,以便将其应用于所有加密的配置或仅应用于特定的web.config。

UseFIPS flag is read from configuration section of RsaProtectedConfigurationProvider. You could set it on machine level (machine.config) so that it's applied to all encrypted configs or only for specific web.config.

对于以后的情况,请在web.config(我已从machine.config复制了该部分并添加了useFIPS = true):

For later case add following section to web.config (I have copied the section from machine.config and added useFIPS="true"):

<configuration>

  <!-- ... -->

  <configProtectedData>
    <providers>
      <remove name="RsaProtectedConfigurationProvider"/>
      <add name="RsaProtectedConfigurationProvider"
           type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
           keyContainerName="NetFrameworkConfigurationKey"
           cspProviderName=""
           useMachineContainer="true"
           useOAEP="false"
           useFIPS="true"
           />
    </providers>
  </configProtectedData>

  <!-- ... -->

</configuration>

现在,如果您运行aspnet_regiis,您将看到数据已使用256位AES加密:

Now if you run aspnet_regiis, you will see that data is encrypted with 256 bit AES:

<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />

AES对称密钥的存储方式与Triple DES模式相同: RSA并嵌入到加密部分中,而RSA密钥存储在机器密钥容器中。请参阅此博客文章有关更多详细信息。

The AES symmetric key is stored in the same way as for Triple DES mode: the key is encrypted with RSA and is embedded into encrypted section while RSA key is stored in machine key container. See this blog post for more details.

我相信,使用已经在 RsaProtectedConfigurationProvider 中实现的AES加密是更好的选择。比自定义AES提供程序。您正在使用现有的密钥存储方法,并且可以防止可能的(高度可能的)安全漏洞。

I believe using of AES encryption that is already implemented in RsaProtectedConfigurationProvider is far better option than custom AES provider. You are using existing key storing method and you are protected from possible (highly probable) security flaws.

这篇关于ASPNET_REGIIS:将AES密钥和IV放入KeyContainer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆