C# 无法使用提供程序“RsaProtectedConfigurationProvider”解密?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16124389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to decrypt using provider 'RsaProtectedConfigurationProvider'?
提问by Mogli
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
在我的 Windows 应用程序中,我试图加密 app.config 文件的连接字符串部分,我的 app.config 文件的连接字符串部分是
<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
在 .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);
}
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.
运行此代码后,我在不同的 app.config 中获得加密的连接字符串,此 app.config 位于 bin\debug 文件夹中,此 .config 文件的名称是 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.
我是第一次这样做,所以不知道如何解决这个问题,陷入困境。
采纳答案by ?iamond ?eeze?
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.
app.config 文件将使用本地计算机上的证书进行加密。该证书不会出现在另一台机器上。因此,您将无法解密 app.config 文件。
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
为此,您需要在您的机器上导出加密密钥,然后在另一台机器上导入它。以下文章演示了如何执行此操作:演练:创建和导出 RSA 密钥容器
回答by Kiquenet
Using this command aspnet_regiis -pa
使用这个命令aspnet_regiis -pa
Open cmd Console -execute as Administrator-
打开cmd控制台-以管理员身份执行-
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
More references:
更多参考:
加密应用程序配置文件时,RsaProtectedConfigurationProvider 有时会失败
ASP.NET Encryption - aspnet_regiis - Farm
ASP.NET 加密 - aspnet_regiis - 农场

