【发布时间】:2015-11-24 15:03:33
【问题描述】:
我编写了一个程序,通过 PrincipalContext 读取我们 Active Directory 中用户的 UserPrincipal。为此,需要对特权用户进行身份验证。 目前,此身份验证的密码以明文形式保存在源代码中。由于安全原因,加密密码应保存在源代码或不同的文件中。 有没有办法解决这个问题?
const string domain = "";
const string rooOrganizationalUnit = "";
const string adDomain = "";
const string adUserName = "";
const string adPassword = "";
private static PrincipalContext GetPrincipalContext()
{
PrincipalContext principalContext;
principalContext = new PrincipalContext(ContextType.Domain, domain, rooOrganizationalUnit, ContextOptions.Negotiate, adUserName + "@" + adDomain, adPassword);
return principalContext;
}
(这个sn-p的代码最初取自这个site)
【问题讨论】:
-
众多选项之一是创建自定义算法来编码/解码文本,创建 DLL 并在此程序中使用编码密码调用它,因此对其他人来说并不容易除非他们获得自定义函数的源代码,否则对其进行解码。
-
为什么不能使用集成安全性?这将消除使用或存储密码的要求。
-
你可以把加密后的字符串放到配置文件里,有办法在编译后把字符串取出来加密,不过在配置文件里更简单。 See this blog entry 了解更多详情。
-
@Nimesh 我发现你的建议有很多问题。 custom 和 security 这两个词不兼容。 Encoded 可以在几毫秒内通过基于频率的现代攻击进行暴力破解。 encoded 和 encrypted 有很大区别。
-
@oleksii 你是对的,我同意,但我没有说这是最好的也是唯一的选择。也可以根据业务重要性选择解决方案。
标签: c# authentication encryption active-directory principalcontext