gpt4 book ai didi

.net - app.config 中的连接字符串。安全性如何?

转载 作者:行者123 更新时间:2023-12-02 06:24:29 32 4
gpt4 key购买 nike

将带有密码的连接字符串放在 app.config 文件中真的是一件好事吗?

在我看来,app.config 没有以任何方式加密,密码信息可以很容易地读取。

我有一个应用程序可以访问目标最终用户没有身份验证的数据库。使用组用户/密码。该应用程序仅在当前 Windows 用户位于 Active Directory 组中时启动。因此,一旦进入应用程序,用户就可以使用组用户连接到数据库。

处理此类连接字符串的正确方法是什么?将它们隐藏在源代码中?

注意这是针对独立应用程序的 - 不是 ASP、IIS 等

这对我有用

(感谢 Jon Galloway - http://weblogs.asp.net/jgalloway/archive/2008/04/13/encrypting-passwords-in-a-net-app-config-file.aspx)

private void EncryptConfigSection()
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.AppSettings;
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
}

这通过在应用程序首次运行时加密 exe 配置文件来实现。我还没有找到在安装过程中执行此操作的方法,因此在应用程序首次启动之前,配置文件是完全可读的。也许有人有想法...

最佳答案

您可以加密部分 app.config 或 web.config 文件,参见 for example this post获取更多信息。

具体来说,this MSDN article介绍了保护连接字符串的各种方法。

关于.net - app.config 中的连接字符串。安全性如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3204288/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com