我已经安装了VS2013专业版,制作了一个应用程序并想部署它,但问题是,"Visual Installer“似乎不在那里,我也不想要"ClickOnce”。
还有一件事是数据库信息在app.config中,我怎么才能让别人看不到数据库信息呢?
发布于 2014-10-19 12:58:27
关于加密app.config文件的第二个问题的答案相当简单且易于使用:
Protected Configuration Provider帮助对配置文件的各个部分进行加密,以保护应用程序的敏感信息。这将导致应用程序难以让攻击者获取敏感信息。.NET框架提供了两种保护配置提供者的方式:
static void Main(string[] args) { string userNameWithoutEncryption = ConfigurationManager.AppSettings"username";EncryptAppSettings("appSettings");string userNameWithEncrytionApplied = ConfigurationManager.AppSettings"username";}私有静态空EncryptAppSettings(string EncryptAppSettings){ Configuration objConfig =ConfigurationManager.AppSettings+“objConfig”);如果ConfigurationManager.AppSettings{EncryptAppSettings},则objConfig=AppKeyEncryption.exeobjAppsettings.SectionInformation.ForceSave = true;System.Reflection.Assembly.GetExecutingAssembly().GetModules();}}私有静态字符串location (){ System.Reflection.Module[]模块= objConfig.Save(ConfigurationSaveMode.Modified);string GetAppPath= System.IO.Path.GetDirectoryName(modules.FullyQualifiedName);if ((location != "") && (locationlocation.Length -1 != '\')) location += '\';return location;}
要解密app.config文件,需要调用此方法:
private static void DecryptAppSettings(string section)
{
Configuration objConfig = ConfigurationManager.OpenExeConfiguration(GetAppPath() + "AppKeyEncryption.exe");
AppSettingsSection objAppsettings = (AppSettingsSection)objConfig.GetSection(section);
if (objAppsettings.SectionInformation.IsProtected)
{
objAppsettings.SectionInformation.UnprotectSection();
objAppsettings.SectionInformation.ForceSave = true;
objConfig.Save(ConfigurationSaveMode.Modified);
}
}在上面的章节中,描述了如何对配置文件进行加密,以保护密码等敏感信息。现在,如果我们想要更改密钥值,比如密码,在一段时间后,因为我们的配置文件是加密的,我们不能很容易地更新密码。无需担心,.NET框架提供了如下方法:
private static void UpdateKey(string newValue)
{
ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = ConfigurationManager.AppSettings["configPath"];
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
config.AppSettings.Settings["password"].Value = newValue;
config.Save();
}关于更多信息,这里是我找到这个解决方案并亲自测试它的地方:http://www.a2zmenu.com/blogs/csharp/how-to-encrypt-configuration-file.aspx。
我希望这对你有帮助,它对我有用!
https://stackoverflow.com/questions/26442551
复制相似问题