【发布时间】:2014-02-25 23:03:56
【问题描述】:
请看下面的代码sn-ps(一个有敏感数据,比如明文密码,另一个加密明文)。我了解如果将这些内容持久化在文件或数据库等中,需要采取预防措施,例如设置 ACL 等,以便攻击者无法轻易获取它们。
但是,如果不需要保留密码怎么办:
方法 2 真的比方法 1 更好,因为密码只在内存中吗?或者,有没有必要?或者,是否有可能有人可以读取内存以获取密码 - 始终建议在内存中或持久化时进行加密?
如果对象被序列化并跨应用程序域传递怎么办? (请注意,我理解如果密码是通过 HTTP(网络)发送的,它需要加密,但如果它只是跨应用程序域,我可以发送纯密码吗?
问候,
纯文本密码代码sn-p
[Serializable]
class PlainTextPassword
{
//Password stored in plain text
private string _plainTextPassword = null;
public PlainTextPassword(string password)
{
this._plainTextPassword = password;
}
public string Password
{
get
{
return this._plainTextPassword;
}
}
}
加密密码sn-p
[Serializable]
class EncryptedPassword
{
//Encrypted password
private string _encryptedPassword = null;
public EncryptedPassword(string password)
{
byte[] encryptedPassword = ProtectedData.Protect(System.Text.Encoding.Unicode.GetBytes(password), null, DataProtectionScope.CurrentUser);
this._encryptedPassword = System.Text.Encoding.Unicode.GetString(encryptedPassword);
}
public string Password
{
get
{
return this._encryptedPassword;
}
}
}
【问题讨论】: