网站here(如下所示)上的代码加密app.config。我按下了一个按钮来加密我的配置。加密配置
当我要运行代码 - (例如在应用程序启动时,如果它尚未加密)? 在我的bin文件夹中,我有2个xml配置文件(Applicationname.exe.config和Applicationname.vshost.exe - 此代码仅对它们中的第一个进行加密 - 当我部署我的程序时,我如何确保我的客户没有意外获得的解密文件还因为这将是一个重大的问题?(或者根本保证这个Windows安装程序照顾)?
C#代码
Configuration config = ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
SectionInformation appSettingsSecInfo = config.GetSection(
"appSettings").SectionInformation;
if (!appSettingsSecInfo.IsProtected)
{
Console.WriteLine("The configuration file has NOT been protected!");
// Encrypt this section by using security provider
// (RsaProtectedConfigurationProvider or DpapiProtectedConfigurationProvider).
appSettingsSecInfo.ProtectSection("RsaProtectedConfigurationProvider");
appSettingsSecInfo.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
我相信我是正确的,你说你需要在安装应用程序时运行它,因为所使用的加密是特定于计算机的。在PC上加密会导致一个配置文件无法在另一台PC上读取。 –
听起来像它可能会打破等方法 - 我会回去看看是否有一个更简单的方法。我无法冒密码开放的风险。谢谢您的帮助。 – user1438082