.net <;连接字符串>;未在app.config中加密节
接下来,我将尝试加密app.config文件中的整个.net <;连接字符串>;未在app.config中加密节,.net,vb.net,encryption,.net,Vb.net,Encryption,接下来,我将尝试加密app.config文件中的整个部分。程序运行时,我可以打开bin/Debug/MyApp.vshost.exe.config,查看是否加密。但是,如果我让程序正常运行、完成并退出,则不会在文件中保存任何内容,就像它刷新所有设置一样 Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) Dim sectio
部分。程序运行时,我可以打开bin/Debug/MyApp.vshost.exe.config
,查看
是否加密。但是,如果我让程序正常运行、完成并退出,则不会在文件中保存任何内容,就像它刷新所有设置一样
Dim config As Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim section As ConnectionStringsSection =
DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
If section.SectionInformation.IsProtected Then
'Remove encryption
section.SectionInformation.UnprotectSection()
Else
'Encrypt
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
End If
section.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Full)
Dim sectionXmlas As String = 'result of encryption
section.SectionInformation.GetRawXml()
要以编程方式实现此功能,您必须调用
config.refreshsection
调用Save将调整物理文件,但在进行上述调用之前,它将缓存在内存中。您必须调用config.refreshsection才能使此工作正常,
配置
类中没有刷新节
命令/函数刷新节
是配置管理器
类中的共享函数。使用要刷新的节名调用ConfigurationManager.RefreshSection(sectionName)
。@duckConfigurationManager.RefreshSection(“连接字符串”)
也没有做任何事情,我想GetRawXML()
在返回数据之前对受保护的部分进行解密-因此您将始终从调用中获取未加密的数据。您能看到基础文件中所做的更改吗<调用ProtectSection()
后,code>section.SectionInformation.IsProtected应返回true。您可能会在该文件的vshost版本中看到一些奇怪的行为。如果直接而不是通过VisualStudio运行程序,会发生什么?你应该看到加密卡在周围。