在我们的程序安装过程中,我们运行此方法来加密 app.config 的部分:
// Get the application configuration file.
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Define the Rsa provider name.
const string provider = "RsaProtectedConfigurationProvider";
// Get the section to protect.
ConfigurationSection connStrings = config.ConnectionStrings;
if (connStrings != null)
{
if (!connStrings.SectionInformation.IsProtected)
{
if (!connStrings.ElementInformation.IsLocked)
{
// Protect the section.
connStrings.SectionInformation.ProtectSection(provider);
connStrings.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
到目前为止工作正常。但是如果我运行这个程序,我们会在几台机器上遇到以下错误“无法使用提供程序‘RsaProtectedConfigurationProvider’解密。来自提供程序的错误消息:无法打开 RSA key 容器”。。
当然我搜索并找到了this help ,但这不起作用。有什么想法吗?
最佳答案
在将 UAC 设置为默认保护的 Win 7 上的 Visual Studio 2010 中调试时,我遇到了类似的问题。
为了解决这个问题,我不得不以管理员身份运行 Visual Studio(“以管理员身份运行”)。
我在尝试运行 aspnet_regiis.exe 来加密我的 web.config 部分时遇到了同样的问题。如果我没有以“管理员身份”运行命令行/控制台,我会收到一个更加神秘的命令行错误:“对象已存在。”
关于c# - 使用 RsaProtectedConfigurationProvider 加密/解密 app.config 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4256569/