无法使用提供程序“RsaProtectedConfigurationProvider”进行解密? [英] Failed to decrypt using provider 'RsaProtectedConfigurationProvider'?

查看:753
本文介绍了无法使用提供程序“RsaProtectedConfigurationProvider”进行解密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 <&的ConnectionStrings GT; 
< add name =SQLiteDBconnectionString =Data Source = | DataDirectory | database.s3db;
Version = 3; password = mypassword;的providerName = System.Data.Sqlite/>
< / connectionStrings>

在.cs文件中我正在加密,如

 配置config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath); 
ConfigurationSection section = config.GetSection(connectionStrings)as ConnectionStringsSection; //可以是任何部分

如果(!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:无法使用提供程序RsaProtectedConfigurationProvider进行解密。来自提供者的错误消息:无法打开RSA密钥容器。 

我第一次这样做,所以不知道如何解决这个问题,很困难。

解决方案

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



为此,您需要在计算机上导出加密密钥,然后将其导入其他机器。以下文章演示了如何做到:演练:创建和导出RSA密钥容器


In my windows application i am trying to encrypt connection string section of app.config file, connection string part of my app.config file is

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

and in .cs file i am encrypting it like

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);
}

after running this code i get encrypted connection string in a different app.config, this app.config resides in bin\debug folder and the name of this .config file is nameofapplication.exe.config.

The problem is when i made setup of this application and run on other machine if gives error that:

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

I am doing it first time so don't know how to solve this, stucked badly in it.

解决方案

The app.config file will have been encrypted using a certificate on your local machine. This certificate will not be present on the other machine. You will therefore not be able to decrypt the app.config file.

For this to work, you need to export the encryption key on your machine, then import it on the other machine. The following article demonstrates how to do that: Walkthrough: Creating and Exporting an RSA Key Container

这篇关于无法使用提供程序“RsaProtectedConfigurationProvider”进行解密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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