Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

c# - Failed to decrypt using provider 'RsaProtectedConfigurationProvider'?

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 bindebug 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using this command aspnet_regiis -pa

Open cmd Console -execute as Administrator-

C:Windowssystem32>aspnet_regiis -pa "NetFrameworkConfigurationKey" "myDomainmyUser"
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

More references:

?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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...