C# 无法为两个部分之一打开RSA密钥容器

C# 无法为两个部分之一打开RSA密钥容器,c#,asp.net,encryption,rsa,rsacryptoserviceprovider,C#,Asp.net,Encryption,Rsa,Rsacryptoserviceprovider,我已经加密了webconfig文件的两个部分,一个叫做ConnectionString,另一个叫做userAccount,使用同一个提供者 在我的代码连接中,字符串部分被解密得很好,没有任何问题,但是当涉及到解密第二个名为userAccounts的部分时,我得到了一个错误 以下是确切的错误消息: 无法使用提供程序“AquedDevProvider”解密。来自提供程序的错误消息:无法打开RSA密钥容器 非常感谢你的帮助 谢谢 以下是web配置文件中的代码 <configProtectedDa

我已经加密了webconfig文件的两个部分,一个叫做ConnectionString,另一个叫做userAccount,使用同一个提供者

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

以下是确切的错误消息:

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

非常感谢你的帮助

谢谢

以下是web配置文件中的代码

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

Rsa密钥
Rsa密钥
这就是我试图从UserAccounts部分访问信息的方式

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

显然,当代码试图检索它在错误的用户帐户下运行的自定义部分时,我能够弄明白这一点(当它试图检索ConnectionString时,这是不同的)。 在尝试访问自定义加密部分时,我使用以下代码查找代码运行的用户帐户

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

向我们展示代码,并向我们展示您的尝试。目前,您只能希望有人处于同一位置,并且有相同的错误消息(您是否尝试加载密钥容器一次而不是两次?这只是一个有根据的猜测?)我已经为问题添加了代码,我加载密钥容器一次,但我使用它解密两个部分ConnectionString和userAccounts。当我试图访问userAccounts部分时收到错误。我对RSA加密非常陌生。如果我能提供更多信息,请告诉我。请将您的答案标记为答案,以简化我们所有人的搜索。
c:\Windows\Microsoft.NET\Framework\v4.0.30319>

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