【问题标题】:Failed to decrypt using provider 'RsaProtectedConfigurationProvider'?无法使用提供程序“RsaProtectedConfigurationProvider”解密?
【发布时间】:2013-04-14 00:19:52
【问题描述】:

在我的 Windows 应用程序中,我试图加密 app.config 文件的连接字符串部分,我的 app.config 文件的连接字符串部分是

<connectionStrings>
<add name="SQLiteDB" connectionString="Data Source=|DataDirectory|database.s3db;    
Version=3;password=mypassword;" providerName="System.Data.Sqlite"/>
</connectionStrings>

在 .cs 文件中我像加密它一样

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
ConfigurationSection section = config.GetSection("connectionStrings") as ConnectionStringsSection; // could be any section

if (!section.IsReadOnly())
{
 section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
 section.SectionInformation.ForceSave = true;
 config.Save(ConfigurationSaveMode.Full);
}

运行此代码后,我在不同的 app.config 中获得了加密的连接字符串,此 app.config 位于 bin\debug 文件夹中,此 .config 文件的名称为 nameofapplication.exe.config。

问题是当我设置此应用程序并在其他机器上运行时如果出现以下错误:

System.Configuration.ConfigurationErrorsException: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.

我是第一次做所以不知道如何解决这个问题,严重卡住了。

【问题讨论】:

    标签: c# visual-studio-2010 encryption setup-deployment


    【解决方案1】:

    使用这个命令aspnet_regiis -pa

    打开cmd控制台-以管理员身份执行-

    C:\Windows\system32>aspnet_regiis -pa "NetFrameworkConfigurationKey" "myDomain\myUser"
    Microsoft (R) ASP.NET RegIIS versión 4.0.30319.33440
    Utilidad de administración que instala y desinstala ASP.NET en el equipo local.
    Copyright (C) Microsoft Corporation. Todos los derechos reservados.
    Agregando ACL para el acceso al contenedor de claves RSA...
    Con éxito
    

    更多参考资料:

    Ɖiamond ǤeezeƦ answer

    The RsaProtectedConfigurationProvider sometimes fails when encrypting an application configuration file

    ASP.NET Encryption - aspnet_regiis - Farm

    Encrypting and Decrypting Web.config Sections in .NET 4.0

    【讨论】:

    • Kiquenet 你拯救了我的一天!将我的笔记本电脑从 Win7 升级到 Win10 后,我一直收到此错误。我所要做的就是按照描述运行aspnet_regiis。现在这一切都再次成为魅力!
    【解决方案2】:

    app.config 文件将使用本地计算机上的证书进行加密。此证书不会出现在另一台机器上。因此,您将无法解密 app.config 文件。

    为此,您需要在您的机器上导出加密密钥,然后在另一台机器上导入它。以下文章演示了如何做到这一点:演练:Creating and Exporting an RSA Key Container

    【讨论】:

    • 仅供参考,或者甚至可能是您将密钥导入另一台机器,在我的情况下是关于许可。当我在 VS 上调试时无法解密,但在我以管理员身份打开 VS 之后。开始解密了。
    猜你喜欢
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 1970-01-01
    • 2023-02-01
    • 2021-01-24
    相关资源
    最近更新 更多