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


C# SecureString.AppendChar方法代码示例

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


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

示例1: CreateCredential

    static SqlCredential CreateCredential(String username)
    {
        // Prompt the user for a password and construct SqlCredential
        SecureString password = new SecureString();
        Console.WriteLine("Enter password for " + username + ": ");

        ConsoleKeyInfo nextKey = Console.ReadKey(true);

        while (nextKey.Key != ConsoleKey.Enter)
        {
            if (nextKey.Key == ConsoleKey.Backspace)
            {
                if (password.Length > 0)
                {
                    password.RemoveAt(password.Length - 1);
                    // erase the last * as well
                    Console.Write(nextKey.KeyChar);
                    Console.Write(" ");
                    Console.Write(nextKey.KeyChar);
                }
            }
            else
            {
                password.AppendChar(nextKey.KeyChar);
                Console.Write("*");
            }
            nextKey = Console.ReadKey(true);
        }

        Console.WriteLine();
        Console.WriteLine();
        password.MakeReadOnly();
        return new SqlCredential(username, password);
    }
开发者ID:CoraBanff,项目名称:sql-server-samples,代码行数:34,代码来源:Program.cs

示例2: GetPassword

    /// <summary>
    /// Read a password from the console into a SecureString
    /// </summary>
    /// <returns>Password stored in a secure string</returns>
    public static SecureString GetPassword()
    {
        SecureString password = new SecureString();
        Console.WriteLine("Enter password: ");

        // get the first character of the password
        ConsoleKeyInfo nextKey = Console.ReadKey(true);
        while (nextKey.Key != ConsoleKey.Enter)
        {
            if (nextKey.Key == ConsoleKey.Backspace)
            {
                if (password.Length > 0)
                {
                    password.RemoveAt(password.Length - 1);

                    // erase the last * as well
                    Console.Write(nextKey.KeyChar);
                    Console.Write(" ");
                    Console.Write(nextKey.KeyChar);
                }
            }
            else
            {
                password.AppendChar(nextKey.KeyChar);
                Console.Write("*");
            }
            nextKey = Console.ReadKey(true);
        }

        Console.WriteLine();

        // lock the password down
        password.MakeReadOnly();
        return password;
    }
开发者ID:repolyo,项目名称:AttendanceLog,代码行数:39,代码来源:index.aspx.cs

示例3: ToSecureString

    /// <summary>
    ///     A String extension method that converts the @this to a secure string.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <returns>@this as a SecureString.</returns>
    public static SecureString ToSecureString(this string @this)
    {
        var secureString = new SecureString();
        foreach (Char c in @this)
            secureString.AppendChar(c);

        return secureString;
    }
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:13,代码来源:String.ToSecureString.cs

示例4: createSecureString

 private static SecureString createSecureString(string s)
 {
     SecureString result = new SecureString();
     foreach(char ch in s)
     {
         result.AppendChar(ch);
     }
     return result;
 }
开发者ID:externl,项目名称:ice,代码行数:9,代码来源:PasswordCallbackI.cs

示例5: ToSecureString

 public static SecureString ToSecureString(string input)
 {
     SecureString secure = new SecureString();
     foreach (char c in input)
     {
         secure.AppendChar(c);
     }
     secure.MakeReadOnly();
     return secure;
 }
开发者ID:hujirong,项目名称:DevOps,代码行数:10,代码来源:DPAPICipher.cs

示例6: ReadPassword

 public static SecureString ReadPassword()
 {
     Console.Write("Password: ");
     SecureString secPass = new SecureString();
     ConsoleKeyInfo key = Console.ReadKey(true);
     while (key.KeyChar != '\r')
     {
         secPass.AppendChar(key.KeyChar);
         key = Console.ReadKey(true);
     }
     return secPass;
 }
开发者ID:Diullei,项目名称:Storm,代码行数:12,代码来源:runas.cs

示例7: ToSecureString

    public static SecureString ToSecureString(this IEnumerable<char> input)
    {
        if (input == null)
        {
            return null;
        }

        var secure = new SecureString();

        foreach (var c in input)
        {
            secure.AppendChar(c);
        }

        secure.MakeReadOnly();
        return secure;
    }
开发者ID:varunrl,项目名称:SSRSCompanion,代码行数:17,代码来源:SecureIt.cs

示例8: Go

   public static void Go() {
      using (SecureString ss = new SecureString()) {
         Console.Write("Please enter password: ");
         while (true) {
            ConsoleKeyInfo cki = Console.ReadKey(true);
            if (cki.Key == ConsoleKey.Enter) break;

            // Append password characters into the SecureString
            ss.AppendChar(cki.KeyChar);
            Console.Write("*");
         }
         Console.WriteLine();

         // Password entered, display it for demonstrattion purposes
         DisplaySecureString(ss);
      }
      // After 'using', the SecureString is Disposed; no sensitive data in memory
   }
开发者ID:Helen1987,项目名称:edu,代码行数:18,代码来源:Ch14-1-CharsAndStrings.cs

示例9: GetSshKey

 public static ISshKey GetSshKey(this EntrySettings settings,
     ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries,
     SprContext sprContext)
 {
     if (!settings.AllowUseOfSshKey) {
     return null;
       }
       KeyFormatter.GetPassphraseCallback getPassphraseCallback =
     delegate(string comment)
     {
       var securePassphrase = new SecureString();
     var passphrase = SprEngine.Compile(strings.ReadSafe(
                   PwDefs.PasswordField), sprContext);
       foreach (var c in passphrase) {
     securePassphrase.AppendChar(c);
       }
       return securePassphrase;
     };
       Func<Stream> getPrivateKeyStream;
       Func<Stream> getPublicKeyStream = null;
       switch (settings.Location.SelectedType) {
     case EntrySettings.LocationType.Attachment:
       if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) {
     throw new NoAttachmentException();
       }
       var privateKeyData = binaries.Get(settings.Location.AttachmentName);
       var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub");
       getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData());
       if (publicKeyData != null)
     getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData());
       return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                    settings.Location.AttachmentName, getPassphraseCallback);
     case EntrySettings.LocationType.File:
       getPrivateKeyStream = () => File.OpenRead(settings.Location.FileName);
       var publicKeyFile = settings.Location.FileName + ".pub";
       if (File.Exists(publicKeyFile))
     getPublicKeyStream = () => File.OpenRead(publicKeyFile);
       return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
                    settings.Location.AttachmentName, getPassphraseCallback);
     default:
       return null;
       }
 }
开发者ID:xenithorb,项目名称:KeeAgent,代码行数:43,代码来源:ExtensionMethods.cs

示例10: FindKeePassPassword

        public static SecureString FindKeePassPassword(
            PwDatabase database,
            bool caseSensitive = false,
            string username = null,
            string url = null,
            string title = null,
            string notes = null)
        {
            var entries =  FindKeePassEntries(database, caseSensitive, true, username, url, title, notes);
            if (entries == null)
                return null;

            foreach(var entry in entries)
            {
                var secureString = new SecureString();
                var value = entry.Strings.ReadSafe("Password");
                foreach (var c in value)
                    secureString.AppendChar(c);

                return secureString;
            }

            return null;
        }
开发者ID:badmishkallc,项目名称:jolt9-devops,代码行数:24,代码来源:Util.cs

示例11: AppendChar

 private static SecureString AppendChar(SecureString ss, char c)
 {
     ss.AppendChar(c);
     return ss;
 }
开发者ID:neutmute,项目名称:exchange-client,代码行数:5,代码来源:SecureStringExtensions.cs

示例12: ThreadSafe_Stress

 public static void ThreadSafe_Stress(int executionTimeSeconds)
 {
     using (var ss = new SecureString())
     {
         DateTimeOffset end = DateTimeOffset.UtcNow + TimeSpan.FromSeconds(executionTimeSeconds);
         Task.WaitAll(Enumerable.Range(0, Environment.ProcessorCount).Select(_ => Task.Run(() =>
         {
             var rand = new Random(Task.CurrentId.Value);
             while (DateTimeOffset.UtcNow < end)
             {
                 char c = (char)rand.Next(0, char.MaxValue);
                 switch (rand.Next(12))
                 {
                     case 0:
                         ss.AppendChar(c);
                         break;
                     case 1:
                         ss.InsertAt(0, c);
                         break;
                     case 2:
                         try { ss.SetAt(0, c); } catch (ArgumentOutOfRangeException) { }
                         break;
                     case 3:
                         ss.Copy().Dispose();
                         break;
                     case 4:
                         Assert.InRange(ss.Length, 0, ushort.MaxValue + 1);
                         break;
                     case 5:
                         ss.Clear();
                         break;
                     case 6:
                         try { ss.RemoveAt(0); } catch (ArgumentOutOfRangeException) { }
                         break;
                     case 7:
                         Assert.False(ss.IsReadOnly());
                         break;
                     case 8:
                         Marshal.ZeroFreeCoTaskMemAnsi(SecureStringMarshal.SecureStringToCoTaskMemAnsi(ss));
                         break;
                     case 9:
                         Marshal.ZeroFreeCoTaskMemUnicode(SecureStringMarshal.SecureStringToCoTaskMemUnicode(ss));
                         break;
                     case 10:
                         Marshal.ZeroFreeGlobalAllocAnsi(SecureStringMarshal.SecureStringToGlobalAllocAnsi(ss));
                         break;
                     case 11:
                         Marshal.ZeroFreeGlobalAllocUnicode(SecureStringMarshal.SecureStringToGlobalAllocUnicode(ss));
                         break;
                 }
             }
         })).ToArray());
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:54,代码来源:SecureStringTests.cs

示例13: createEventQuery

    private EventLogReader createEventQuery(EmployeeProfile emp)
    {
        DateTime now = DateTime.Now;
        DateTime endDate = now;
        DateTime startDate = DateTime.Today.AddDays(AppConfig.DisplayDays * -1);
        Session["DateTime"] = startDate;

        string queryString = String.Format(AppConfig.EventQuery,
                startDate.ToUniversalTime().ToString("o"),
                endDate.ToUniversalTime().ToString("o"));
        EventLogQuery query = new EventLogQuery("System", PathType.LogName, queryString);
        if (emp.Machine.CompareTo("127.0.0.1") != 0 && AppConfig.RemoteQuery) {
            // Query the Application log on the remote computer.
            SecureString pw = new SecureString();
            string passwd = emp.Password;
            if (!string.IsNullOrEmpty(passwd)) {
                char[] charArray = passwd.ToCharArray();
                for (int i = 0; i < passwd.Length; i++) { pw.AppendChar(charArray[i]); }
            }
            pw.MakeReadOnly();
            query.Session = new EventLogSession(
                emp.Machine, // Remote Computer
                emp.Domain, // Domain
                emp.Name,   // Username
                pw,
                SessionAuthentication.Default);
            //pw.Dispose();
            Session["SecureString"] = pw;
        }
        Session["EventLogQuery"] = queryString;
        return new EventLogReader(query);
    }
开发者ID:repolyo,项目名称:AttendanceLog,代码行数:32,代码来源:index.aspx.cs

示例14: CreatePfxDataPasswordSecureString

        public static SecureString CreatePfxDataPasswordSecureString()
        {
            var s = new SecureString();

            // WARNING:
            // A key value of SecureString is in keeping string data off of the GC heap, such that it can
            // be reliably cleared when no longer needed.  Creating a SecureString from a string or converting
            // a SecureString to a string diminishes that value. These conversion functions are for testing that
            // SecureString works, and does not represent a pattern to follow in any non-test situation.
            foreach (char c in PfxDataPassword.ToCharArray())
            {
                s.AppendChar(c);
            }

            return s;
        }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:TestData.cs

示例15: ConvertToSecureString

    private SecureString ConvertToSecureString(string password)
    {
        if (password == null)
            throw new ArgumentNullException("password");

        var securePassword = new SecureString();
        foreach (char c in password)
            securePassword.AppendChar(c);
        securePassword.MakeReadOnly();
        return securePassword;
    }
开发者ID:slemoineizysolutions,项目名称:server-monitoring,代码行数:11,代码来源:Serveur.aspx.cs


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