Csharp/C#教程:如何加密app.config?分享


如何加密app.config?

在wpf中创建app.config(c#)

       

用过的代码C#:

  Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConnectionStringsSection conStr = config.ConnectionStrings; if (!conStr.SectionInformation.IsProtected) { conStr.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider"); conStr.SectionInformation.ForceSave = true; config.Save(); } else { foreach (ConnectionStringSettings ss in conStr.ConnectionStrings) Console.WriteLine(ss); Console.Read(); } 

config.Save(); – 导致exception:

{“无法使用提供程序’RsaProtectedConfigurationProvider’加密’connectionStrings’部分。来自提供程序的错误消息:对象已存在。 r n”}}

检查SectionInformation.ProtectSection方法

还请看这里

我在Save上得到了同样的例外。 通过以管理员身份运行应用程序,我能够解决这个问题。

我在我的项目中添加了一个app.manifest文件,并改变了执行级别,如下所示:requestedExecutionLevel level =“requireAdministrator”uiAccess =“false”

这样,我总是以管理员身份运行,并且有权保存加密部分。

您可以查看使用aspnet_regiis.exe为您执行加密。 请参阅此MSDN链接

这样,您无需编写代码即可执行加密。

上述就是C#学习教程:如何加密app.config?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1027138.html

(0)
上一篇 2022年1月9日
下一篇 2022年1月9日

精彩推荐