易丰科技

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3246|回复: 0
打印 上一主题 下一主题

C# 以前没用过的一个类 SecureString

[复制链接]

111

主题

117

帖子

3588

积分

论坛元老

Rank: 8Rank: 8

积分
3588
跳转到指定楼层
楼主
发表于 2011-10-3 20:18:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  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.             }
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|易丰科技

GMT+8, 2024-10-12 11:21 , Processed in 0.042385 second(s), 20 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表