ifi*_*lay 7 .net c# encryption settings user.config
我正在Windows 8.1上使用C#.NET4.0 VS2010开发Windows桌面应用程序.我使用.NET设置机制存储了一系列设置.它们具有用户范围,因此,在应用程序中设置时,它们将写入Users\username\AppData\Local\companyname\App.exe_URL_randomstuff\versionno\user.config.
这些设置包括我需要隐藏的一些用户注册信息.我的研究表明我应该能够使用RsaProtectedConfigurationProvider加密设置,但我发现的所有示例都与加密app.config而不是user.config有关(例如http://msdn.microsoft.com/en-us /library/system.configuration.rsaprotectedconfigurationprovider.aspx).
因此,我的问题是可以加密user.config,如果是这样,怎么办?我注意到当我实例化System.Configuration.Configuration对象时,我可以将ConfigurationUserLevel设置为PerUserRoamingAndLocal.当我通过调试器检查对象时,它似乎引用了正确的user.config文件,但是当我继续实例时,一个ConfigurationSection来保护它返回null.代码如下所示:
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.PerUserRoamingAndLocal);
ConfigurationSection connStrings = config.AppSettings;
connStrings.SectionInformation.ProtectSection(provider);
Run Code Online (Sandbox Code Playgroud)
我认为config.AppSettings可能不正确,但我不知道该替换它.
任何建议都非常感谢.
现在就搞定了.我使用ConfigurationUserLevel.PerUserRoamingAndLocal来访问我的user.config文件是正确的.问题出在config.AppSettings上.我在正确的轨道上用config.GetSection("Progname.Properties.Settings")替换它,但我的命名错误.现在的工作代码如下:
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.PerUserRoamingAndLocal);
ConfigurationSection connStrings = config.GetSection("userSettings/Progname.Properties.Settings");
connStrings.SectionInformation.ProtectSection(provider);
Run Code Online (Sandbox Code Playgroud)
"Progname"就是你的集会所谓的.感谢@neoistheone和@hatchet的输入.
归档时间: |
|
查看次数: |
4287 次 |
最近记录: |