易丰科技

标题: C# 以前没用过的一个类 SecureString [打印本页]

作者: Calvin    时间: 2011-10-3 20:18
标题: C# 以前没用过的一个类 SecureString
  1. // Instantiate the secure string.
  2.             SecureString securePwd = new SecureString();
  3.             ConsoleKeyInfo key;

  4.             Console.Write("Enter password: ");
  5.             do
  6.             {
  7.                 key = Console.ReadKey(true);

  8.                 // Ignore any key out of range.
  9.                 if (((int)key.Key) >= 48 && ((int)key.Key <= 90))
  10.                 {
  11.                     // Append the character to the password.
  12.                     securePwd.AppendChar(key.KeyChar);
  13.                     Console.Write("*");
  14.                 }
  15.                 // Exit if Enter key is pressed.
  16.             } while (key.Key != ConsoleKey.Enter);
  17.             Console.WriteLine();

  18.             try
  19.             {
  20.                 Process.Start("Notepad.exe", "calvin", securePwd, "PC-05");
  21.             }
  22.             catch (Win32Exception e)
  23.             {
  24.                 Console.WriteLine(e.Message);
  25.             }
复制代码






欢迎光临 易丰科技 (http://forum.yftek.com/) Powered by Discuz! X3