7

私の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.

私はそれを初めてやっているので、これを解決する方法がわかりません。

4

2 に答える 2