【问题标题】:The RSA key container could not be opened for one of two sections无法为两个部分之一打开 RSA 密钥容器
【发布时间】:2013-08-27 00:36:48
【问题描述】:

我已经加密了 webconfig 文件的两个部分,一个称为 connectionStrings,另一个是使用相同 Provider 的 userAccount。

在我的代码中,connectionString 部分被解密得很好,没有任何问题,但是当涉及到解密名为 userAccounts 的第二部分时,我得到了一个错误。

这是确切的错误消息:

使用提供程序“AqueductDevProvider”解密失败。来自提供程序的错误消息:无法打开 RSA 密钥容器。

您的帮助将不胜感激。

谢谢

这是网页配置文件中的代码

<configProtectedData>
    <providers>
        <add name="AqueductDevProvider"
             type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,&#xD;&#xA;Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,&#xD;&#xA;processorArchitecture=MSIL"
             keyContainerName="AqueductDevKeys"
             useMachineContainer="true" />
    </providers>
</configProtectedData>

<connectionStrings configProtectionProvider="AqueductDevProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
                <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
                <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                    <KeyName>Rsa Key</KeyName>
                </KeyInfo>
                <CipherData>
                <CipherValue></CipherValue>
                </CipherData>
            </EncryptedKey>
        </KeyInfo>
        <CipherData>
                <CipherValue></CipherValue>
        </CipherData>
    </EncryptedData>
</connectionStrings>
<userAccounts configProtectionProvider="AqueductDevProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns="http://www.w3.org/2001/04/xmlenc#">
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
                <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
                <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
                    <KeyName>Rsa Key</KeyName>
                </KeyInfo>
                <CipherData>
                <CipherValue></CipherValue>
                </CipherData>
            </EncryptedKey>
        </KeyInfo>
        <CipherData>
                <CipherValue></CipherValue>
        </CipherData>
    </EncryptedData>
</userAccounts>

这就是我尝试从 UserAccounts 部分访问信息的方式

System.Configuration.ConfigurationManager.AppSettings["AdminName"]; userAccounts 中有一个名为 AdminName 的密钥,该密钥已加密

【问题讨论】:

  • 向我们展示代码并向我们展示您的尝试。目前你只能希望有人在同一个地方并且有相同的错误消息(你尝试加载密钥容器一次而不是两次 - 只是一个有根据的猜测?)
  • 我已经在问题中添加了代码,我正在加载一次密钥容器,但我正在使用它解密两个部分 connectionStrings 和 userAccounts。当我尝试访问 userAccounts 部分时收到错误消息。我对 RSA 加密非常陌生。如果我能提供更多信息,请告诉我。

标签: c# asp.net encryption rsa rsacryptoserviceprovider


【解决方案1】:

我能够弄清楚这一点,显然当代码试图检索它在错误的用户帐户下运行的自定义部分时(当它试图检索连接字符串时是不同的)。 在尝试访问自定义加密部分时,我使用以下代码找出我的代码在哪个用户帐户下运行。

<% Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name);%>

结果是 NT AUTHORITY\IUSR

在这之后我所要做的就是在这个目录下运行以下命令

c:\Windows\Microsoft.NET\Framework\v4.0.30319>

aspnet_regiis.exe -pa "AqueductDevKeys" "NT AUTHORITY\IUSR"

【讨论】:

  • 请将您的答案标记为答案,以简化我们所有人的搜索。
猜你喜欢
  • 2011-02-24
  • 1970-01-01
  • 2014-06-16
  • 1970-01-01
  • 1970-01-01
  • 2011-06-12
  • 1970-01-01
  • 2012-05-08
  • 2018-07-16
相关资源
最近更新 更多