【发布时间】: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