当前位置: 首页>>代码示例>>C#>>正文


C# SecureString.Clear方法代码示例

本文整理汇总了C#中System.Security.SecureString.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.Clear方法的具体用法?C# SecureString.Clear怎么用?C# SecureString.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.SecureString的用法示例。


在下文中一共展示了SecureString.Clear方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnsafeConstructor

		public unsafe void UnsafeConstructor ()
		{
			try {
				SecureString ss = null;
				char[] data = new char[] { 'a', 'b', 'c' };
				fixed (char* p = &data[0]) {
					ss = new SecureString (p, data.Length);
				}
				Assert.IsFalse (ss.IsReadOnly (), "IsReadOnly");
				Assert.AreEqual (3, ss.Length, "3");
				ss.AppendChar ('a');
				Assert.AreEqual (4, ss.Length, "4");
				ss.Clear ();
				Assert.AreEqual (0, ss.Length, "0b");
				ss.InsertAt (0, 'b');
				Assert.AreEqual (1, ss.Length, "1b");
				ss.SetAt (0, 'c');
				Assert.AreEqual (1, ss.Length, "1c");
				ss.RemoveAt (0);
				Assert.AreEqual (0, ss.Length, "0c");
				ss.Dispose ();
			}
			catch (NotSupportedException) {
				Assert.Ignore (NotSupported);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:26,代码来源:SecureStringTest.cs

示例2: ReadLine

        public SecureString ReadLine()
        {
            // make sure Ctrl+C can abort editing
            _mainThread = Thread.CurrentThread;
            Console.CancelKeyPress += InterruptEdit;

            SecureString buffer = new SecureString();
            var finished = false;
            while (!finished)
            {
                try
                {
                    finished = ReadKey(buffer);
                }
                catch (ThreadAbortException)
                {
                    // thrown on Ctrl+C
                    Thread.ResetAbort();
                    buffer.Clear();
                    buffer = null;
                    break;
                }
            }

            Console.WriteLine();
            // reset Ctrl+C handling
            Console.CancelKeyPress -= InterruptEdit;
            return buffer;
        }
开发者ID:mauve,项目名称:Pash,代码行数:29,代码来源:SecureStringReader.cs

示例3: ComposeFile

		public static void ComposeFile(BinaryWriter writer, string username, SecureString password,
			long IP, ushort port, string databaseName)
		{
			byte[] encodedDbName = UTF8.GetBytes(databaseName);
			byte[] encodedPassword = UTF8.GetBytes(ConvertToUnsecureString(password));
			byte[] encodedUsername = UTF8.GetBytes(username);
			byte[] publicKey = GenerateRandomASCIChars(ENCODING_LENGTH);

			byte[] encryptedPassword;

			using (SHA1 sha = new SHA1CryptoServiceProvider())
			{
				encryptedPassword = AESEncryption.Encrypt(sha.ComputeHash(encodedPassword), publicKey, PRIVATE_VECTOR, PRIVATE_KEY);
			}

			password.Clear();
			DestroyData(encodedPassword);

			writer.Write(IP);
			writer.Write(port);
			writer.Write(encodedUsername.Length);
			writer.Write(encodedUsername);
			writer.Write(encodedDbName.Length);
			writer.Write(encodedDbName);
			writer.Write(publicKey.Length);
			writer.Write(publicKey);
			writer.Write(encryptedPassword.Length);
			writer.Write(encryptedPassword);

			DestroyData(encryptedPassword);
		}
开发者ID:BjkGkh,项目名称:R106,代码行数:31,代码来源:GlobalInformationService.cs

示例4: ToSecureString

        public static void ToSecureString(this String value, SecureString secureString)
        {
            secureString.Clear();

            if (value != null)
            {
                Array.ForEach(value.ToArray(), secureString.AppendChar);
                secureString.MakeReadOnly();
            }
        }
开发者ID:arusland,项目名称:dax,代码行数:10,代码来源:StringExtensions.cs

示例5: GetPasswordFromConsole

        private static SecureString GetPasswordFromConsole()
        {
            SecureString password = new SecureString();
            bool readingPassword = true;

            Console.Write("Enter password: ");

            while (readingPassword)
            {
                ConsoleKeyInfo userInput = Console.ReadKey(true);

                switch (userInput.Key)
                {
                    case (ConsoleKey.Enter):
                        readingPassword = false;
                        break;
                    case (ConsoleKey.Escape):
                        password.Clear();
                        readingPassword = false;
                        break;
                    case (ConsoleKey.Backspace):
                        if (password.Length > 0)
                        {
                            password.RemoveAt(password.Length - 1);
                            Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                            Console.Write(" ");
                            Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        }
                        break;
                    default:
                        if (userInput.KeyChar != 0)
                        {
                            password.AppendChar(userInput.KeyChar);
                            Console.Write("*");
                        }
                        break;
                }
            }
            Console.WriteLine();

            password.MakeReadOnly();
            return password;
        }
开发者ID:masa67,项目名称:GetStartedEWS,代码行数:43,代码来源:Program.cs

示例6: RenameComputer

    public RenameComputer(string computerName, string newComputerName)
    {
        ps = PowerShell.Create();

        domainUName = System.Configuration.ConfigurationManager.AppSettings["AddCUser"];
        domainPWord = System.Configuration.ConfigurationManager.AppSettings["AddCPW"];
        localUName = System.Configuration.ConfigurationManager.AppSettings["AdminUser"];
        localPWord = System.Configuration.ConfigurationManager.AppSettings["AdminPW"];

        securestring = new System.Security.SecureString();
        foreach (char c in localPWord) { securestring.AppendChar(c); }
        localCred = new PSCredential(domainUName, securestring);
        securestring.Clear();
        foreach (char c in domainPWord) { securestring.AppendChar(c); }
        domainCred = new PSCredential(domainUName, securestring);

        parameters = new List<string>();
        this.computerName = computerName;
        this.newComputerName = newComputerName;
    }
开发者ID:jlam916,项目名称:ServiceDesk,代码行数:20,代码来源:RenameComputer.cs

示例7: DefaultConstructor

		public void DefaultConstructor ()
		{
			try {
				SecureString ss = new SecureString ();
				Assert.IsFalse (ss.IsReadOnly (), "IsReadOnly");
				Assert.AreEqual (0, ss.Length, "0");
				ss.AppendChar ('a');
				Assert.AreEqual (1, ss.Length, "1");
				ss.Clear ();
				Assert.AreEqual (0, ss.Length, "0b");
				ss.InsertAt (0, 'b');
				Assert.AreEqual (1, ss.Length, "1b");
				ss.SetAt (0, 'c');
				Assert.AreEqual (1, ss.Length, "1c");
				Assert.AreEqual ("System.Security.SecureString", ss.ToString (), "ToString");
				ss.RemoveAt (0);
				Assert.AreEqual (0, ss.Length, "0c");
				ss.Dispose ();
			}
			catch (NotSupportedException) {
				Assert.Ignore (NotSupported);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:23,代码来源:SecureStringTest.cs


注:本文中的System.Security.SecureString.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。