无法为两个部分中的一个打开RSA密钥容器

本文关键字:一个 RSA 密钥 两个 | 更新日期: 2023-09-27 18:29:01

我已经使用相同的Provider加密了webconfig文件的两个部分,一个称为connectionStrings,另一个为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>

这就是我试图从用户帐户部分访问信息的方式

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

无法为两个部分中的一个打开RSA密钥容器

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

<% 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"