0
我想創建一個變量,一個安全的變量,它或多或少是我的代碼中使用的CONST。我研究過使用System.Security.SecureString,看起來它可能是票據,因爲我不希望用戶找出這個密碼。初始化它唯一的問題。在大多數情況下,它看起來像SecureString最好由用戶按鍵「設置」。我不想要這個。一種選擇我來翻過看起來是這樣的:如何將SecureString初始化爲只讀
unsafe public static void Main()
{
SecureString testString;
// Define the string value to assign to a new secure string.
char[] chars = { 't', 'e', 's', 't' };
// Instantiate a new secure string.
fixed(char* pChars = chars)
{
testString = new SecureString(pChars, chars.Length);
}
// Display secure string length.
Console.WriteLine("The length of the string is {0} characters.",
testString.Length);
}
唯一的問題是,該字符數組「T」,「E」,「S」,「T」很可能仍然在內存擠在一起編譯後。有沒有什麼好的方法可以在編譯時間之前將SecureString的值設置爲一個常量值並將該值置亂?
你想完成什麼?你想存儲一個'祕密'密碼來隱藏一些功能?代碼泄露/發現的那一刻,你就'安全'消失了!一個更好的解決方案,但仍然不是很好,是有你的應用程序。打電話回家。 – 2009-07-29 22:27:54