Failed to decrypt the use of the "RsaProtectedConfigurationProvider" provider?

In my Windows application, I'm trying to encrypt the connection string line of the app.config file, the connection string string of my app.config file

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

and in the .cs file I encrypt it as

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 an encrypted connection string in another app.config, this app.config file is in the bin \ debug folder, and the name of this .config file is nameofapplication.exe.config.

The problem is that I created the setup for this application and run it on another machine if it gives an error:

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 this for the first time, so I don’t know how to solve it, I’m very stuck in it.

+5
source share
2 answers

app.config . . app.config.

, . , : : RSA

+3

aspnet_regiis -pa

cmd -execute as Administrator -

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Ʀ

RsaProtectedConfigurationProvider

ASP.NET - aspnet_regiis -

Web.config .NET 4.0

+6

All Articles