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


C# SecureString.RemoveAt方法代码示例

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


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

示例1: GetSecureStringFromConsole

        public static SecureString GetSecureStringFromConsole()
        {
            var password = new SecureString();

            Console.Write("Enter Password: ");
            while (true)
            {
                ConsoleKeyInfo cki = Console.ReadKey(true);

                if (cki.Key == ConsoleKey.Enter) break;
                if (cki.Key == ConsoleKey.Escape)
                {
                    password.Dispose();
                    return null;
                }
                if (cki.Key == ConsoleKey.Backspace)
                {
                    if (password.Length != 0)
                        password.RemoveAt(password.Length - 1);
                }
                else password.AppendChar(cki.KeyChar);
            }

            return password;
        }
开发者ID:virajs,项目名称:klWCFSecurity,代码行数:25,代码来源:klWCFCryptoHelper.cs

示例2: ReadPassword

        /// <summary>
        /// Reads a password from the user in a safe fashion.
        /// </summary>
        /// <param name="prompt">A string, shown to the user as prompt.</param>
        /// <returns>An instance of <see cref="SecureString"/>.</returns>
        public SecureString ReadPassword(string prompt)
        {
            Console.WriteLine(prompt);

            // http://stackoverflow.com/questions/3404421/password-masking-console-application

            Console.Write("Password: ");
            SecureString pwd = new SecureString();
            while (true)
            {
                ConsoleKeyInfo i = Console.ReadKey(true);
                if (i.Key == ConsoleKey.Enter)
                {
                    break;
                }
                else if (i.Key == ConsoleKey.Backspace)
                {
                    if (pwd.Length > 0)
                    {
                        pwd.RemoveAt(pwd.Length - 1);
                        //Console.Write("\b \b");
                    }
                }
                else
                {
                    pwd.AppendChar(i.KeyChar);
                    //Console.Write("*");
                }
            }
            Console.WriteLine();
            return pwd;
        }
开发者ID:mastersign,项目名称:bench,代码行数:37,代码来源:ConsoleUI.cs

示例3: takePassword

		private SecureString takePassword ()
		{
			SecureString result = new SecureString();

			Console.Write("Password: ");
			while (true)
			{
				ConsoleKeyInfo i = Console.ReadKey(true);
				if (i.Key == ConsoleKey.Enter)
				{
					break;
				}
				else if (i.Key == ConsoleKey.Backspace)
				{
					if (result.Length > 0)
					{
						result.RemoveAt(result.Length - 1);
						Console.Write("\b \b");
					}
				}
				else if (i.Key == ConsoleKey.Spacebar || result.Length > 20) {}
				else
				{
					result.AppendChar(i.KeyChar);
					Console.Write("*");
				}
			}
			Console.WriteLine();

			return result;
		}
开发者ID:frachstudia,项目名称:studies,代码行数:31,代码来源:Client.cs

示例4: GetPassword

        /// <summary>
        /// Get a password from the console
        /// </summary>
        /// <returns>Password stored in a SecureString</returns>
        private static SecureString GetPassword()
        {
            var password = new SecureString();
            while (true)
            {
                var keyInfo = Console.ReadKey(true);
                if (keyInfo.Key == ConsoleKey.Enter)
                {
                    break;
                }

                if (keyInfo.Key == ConsoleKey.Backspace)
                {
                    if (password.Length > 0)
                    {
                        password.RemoveAt(password.Length - 1);
                        Console.Write("\b \b");
                    }
                }
                else
                {
                    password.AppendChar(keyInfo.KeyChar);
                    Console.Write("*");
                }
            }
            return password;
        }
开发者ID:huoxudong125,项目名称:SourceBrowser,代码行数:31,代码来源:WebProxyAuthenticator.cs

示例5: ReadConsoleByKeySecure

 public static SecureString ReadConsoleByKeySecure(bool hideCharacters = false)
 {
     var running = true;
     var finalString = new SecureString();
     while (running)
     {
         var letter = Console.ReadKey(hideCharacters).KeyChar;
         if (letter == (char)13)
             running = false;
         else if (letter == (char)8 && finalString.Length >= 1)
         {
             finalString.RemoveAt(finalString.Length - 1);
             Console.CursorLeft--;
             Console.Write('\0');
             Console.CursorLeft--;
         }
         else if (letter != (char)8)
         {
             finalString.AppendChar(letter);
             if (hideCharacters)
                 Console.Write('*');
         }
     }
     Console.WriteLine();
     return finalString;
 }
开发者ID:Sharpiro,项目名称:DotnetCoreTools,代码行数:26,代码来源:StringExtensions.cs

示例6: 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

示例7: EnterPassword

 public static SecureString EnterPassword()
 {
     SecureString pwd = new SecureString();
     while (true)
     {
         ConsoleKeyInfo i = Console.ReadKey(true);
         if (i.Key == ConsoleKey.Enter)
         {
             break;
         }
         else if (i.Key == ConsoleKey.Backspace)
         {
             if (pwd.Length > 0)
             {
                 pwd.RemoveAt(pwd.Length - 1);
                 Console.Write("\b \b");
             }
         }
         else
         {
             pwd.AppendChar(i.KeyChar);
             Console.Write("*");
         }
     }
     return pwd;
 }
开发者ID:heimanhon,项目名称:researchwork,代码行数:26,代码来源:Utilities.cs

示例8: ReadPasswordFromConsole

        /// <summary>
        /// Read a password from the console and return it as SecureString
        /// </summary>
        /// <returns></returns>
        public static bool ReadPasswordFromConsole(out SecureString secStr)
        {
            secStr = new SecureString();

            for (ConsoleKeyInfo c = Console.ReadKey(true); c.Key != ConsoleKey.Enter; c = Console.ReadKey(true))
            {
                if (c.Key == ConsoleKey.Backspace && secStr.Length > 0)
                    secStr.RemoveAt(secStr.Length - 1);

                if (c.Key == ConsoleKey.Escape)
                {
                    // cancel
                    secStr.Dispose();
                    Console.WriteLine();
                    return false;
                }

                if (!Char.IsControl(c.KeyChar))
                    secStr.AppendChar(c.KeyChar);
            }

            secStr.MakeReadOnly();
            Console.WriteLine();
            return true;
        }
开发者ID:cherepets,项目名称:SeafClient,代码行数:29,代码来源:SecureStringUtils.cs

示例9: ReadSecureString

 public static SecureString ReadSecureString(string prompt)
 {
     const string t = " !\"#$%&'()*+,-./0123456789:;<=>[email protected][\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
     SecureString securePwd = new SecureString();
     ConsoleKeyInfo key;
     Console.Write(prompt);
     Console.Write(':');
     do
     {
         key = Console.ReadKey(true);
         if (t.IndexOf(key.KeyChar) != -1)
         {
             securePwd.AppendChar(key.KeyChar);
             Console.Write('*');
         }
         else if (key.Key == ConsoleKey.Backspace && securePwd.Length > 0)
         {
             securePwd.RemoveAt(securePwd.Length - 1);
             Console.Write(key.KeyChar);
             Console.Write(' ');
             Console.Write(key.KeyChar);
         }
     } while (key.Key != ConsoleKey.Enter);
     Console.WriteLine();
     securePwd.MakeReadOnly();
     return securePwd;
 }
开发者ID:zhengger,项目名称:AntShares,代码行数:27,代码来源:ConsoleServiceBase.cs

示例10: SecureStringUsingExample

        // secure string for passwords or secret string data
        public static void SecureStringUsingExample()
        {
            using (SecureString securePassword = new SecureString())
            {
                // getting
                while (true)
                {
                    ConsoleKeyInfo cki = Console.ReadKey(true);


                    if (cki.Key == ConsoleKey.Enter)
                    {
                        Console.WriteLine();
                        break;
                    }

                    if (cki.Key == ConsoleKey.Backspace)
                    {
                        if (securePassword.Length > 0)
                        {
                            securePassword.RemoveAt(securePassword.Length - 1);
                            Console.Write("-");
                        }
                        continue;
                    }

                    securePassword.AppendChar(cki.KeyChar);
                    Console.Write("*");
                }


                // showing
                unsafe
                {
                    char* buffer = null;

                    try
                    {
                        // decrypting
                        buffer = (char*)Marshal.SecureStringToCoTaskMemUnicode(securePassword);

                        for (var i = 0; buffer[i] != 0; i++)
                            Console.Write(buffer[i]);
                    }
                    finally
                    {
                        // buffer clearing
                        if (buffer != null) Marshal.ZeroFreeCoTaskMemUnicode((IntPtr)buffer);
                    }
                }


                securePassword.Dispose(); // not necessary in using construction
            }
        }
开发者ID:Menaver,项目名称:Drafts,代码行数:56,代码来源:Security.cs

示例11: 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

示例12: ReadLineAsSecureString

        public static SecureString ReadLineAsSecureString()
        {
            var secureString = new SecureString();

            try
            {
                ConsoleKeyInfo keyInfo;
                while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Enter)
                {
                    if (keyInfo.Key == ConsoleKey.Backspace)
                    {
                        if (secureString.Length < 1)
                        {
                            continue;
                        }
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        Console.Write(' ');
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        secureString.RemoveAt(secureString.Length - 1);
                    }
                    else
                    {
                        secureString.AppendChar(keyInfo.KeyChar);
                        Console.Write('*');
                    }
                }
                Console.WriteLine(String.Empty);
            }
            catch (InvalidOperationException)
            {
                // This can happen when you redirect nuget.exe input, either from the shell with "<" or 
                // from code with ProcessStartInfo. 
                // In this case, just read data from Console.ReadLine()
                foreach (var c in Console.ReadLine())
                {
                    secureString.AppendChar(c);
                }
            }

            secureString.MakeReadOnly();
            return secureString;
        }
开发者ID:themotleyfool,项目名称:NuGet,代码行数:42,代码来源:ConsoleCredentialProvider.cs

示例13: ReadKey

 private bool ReadKey(SecureString buffer)
 {
     ConsoleKeyInfo i = Console.ReadKey(true);
     if (i.Key == ConsoleKey.Enter)
     {
         return true;
     }
     else if (i.Key == ConsoleKey.Backspace)
     {
         if (buffer.Length > 0)
         {
             buffer.RemoveAt(buffer.Length - 1);
             Console.Write("\b \b");
         }
     }
     else
     {
         buffer.AppendChar(i.KeyChar);
         Console.Write("*");
     }
     return false;
 }
开发者ID:mauve,项目名称:Pash,代码行数:22,代码来源:SecureStringReader.cs

示例14: 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

示例15: GetPassword

        /// <summary>
        /// Helper to return the password
        /// </summary>
        /// <returns>SecureString representing the password</returns>
        public static SecureString GetPassword()
        {
            SecureString sStrPwd = new SecureString();

            try
            {
                Console.Write("SharePoint Password: ");

                for (ConsoleKeyInfo keyInfo = Console.ReadKey(true); keyInfo.Key != ConsoleKey.Enter; keyInfo = Console.ReadKey(true))
                {
                    if (keyInfo.Key == ConsoleKey.Backspace)
                    {
                        if (sStrPwd.Length > 0)
                        {
                            sStrPwd.RemoveAt(sStrPwd.Length - 1);
                            Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                            Console.Write(" ");
                            Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
                        }
                    }
                    else if (keyInfo.Key != ConsoleKey.Enter)
                    {
                        Console.Write("*");
                        sStrPwd.AppendChar(keyInfo.KeyChar);
                    }

                }
                Console.WriteLine("");
            }
            catch (Exception e)
            {
                sStrPwd = null;
                Console.WriteLine(e.Message);
            }

            return sStrPwd;
        }
开发者ID:BNATENSTEDT,项目名称:PnP,代码行数:41,代码来源:Program.cs


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