[英]Can password be stored in plain text as long as its in memory, and not persisted in database, files etc.?
請參見下面的代碼片段(其中一個包含敏感數據(如純文本中的密碼),另一個包含對純文本進行加密)。 我了解如果有人將其持久保存在文件或數據庫等中,則需要采取諸如設置ACL等的預防措施,以使攻擊者無法輕松地獲取它們。
但是,如果不需要保留密碼怎么辦:
因為密碼僅在內存中,方法2真的比方法1好嗎? 還是沒有必要? 或者,是否有可能有人可以讀取內存以獲取密碼-始終建議在內存中或持久保存時進行加密?
如果對象已序列化並在應用程序域之間傳遞怎么辦? (請注意,我知道密碼是否通過HTTP(網絡)發送,需要進行加密,但是如果僅在應用程序域之間可以發送普通密碼?
問候,
純文本密碼代碼段
[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;
}
}
}
加密的密碼代碼段
[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;
}
}
}
就內存快照而言,方法2)的安全性不及1)。 您無法控制GC釋放原始密碼的時間(因為您幾乎無法控制GC)-因此,如果要針對內存快照進行安全性拍攝,請查看
SecureString
參考: http : //msdn.microsoft.com/zh-cn/library/system.security.securestring(v=vs.110).aspx
至於可以拍攝內存快照的工具,請看一下一些探查器(例如Dynatrace)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.