コード例 #1
0
        private static void HashPassword(string passwordToHash, int numberOfRounds)
        {
            var sw = new Stopwatch();

            sw.Start();

            var hashedPassword = PasswordSecurity.HashPassword(Encoding.UTF8.GetBytes(passwordToHash),
                                                               PasswordSecurity.GenerateSalt(),
                                                               numberOfRounds);

            sw.Stop();

            Console.WriteLine();
            Console.WriteLine("Password to hash : " + passwordToHash);
            Console.WriteLine("Hashed Password : "******"Iteration <" + numberOfRounds + "> Elapsed Time : " + sw.ElapsedMilliseconds);
        }
コード例 #2
0
        public static void PasswordWithSalt()
        {
            const string password = "******";

            byte[] salt = PasswordSecurity.GenerateSalt();

            Console.WriteLine("Hash Password with Salt Demonstration in .NET");
            Console.WriteLine("..............................................");
            Console.WriteLine();
            Console.WriteLine("Password : "******"Salt = " + Convert.ToBase64String(salt));
            Console.WriteLine();

            var hashedPassword1 = PasswordSecurity.HashPasswordWithSalt(
                Encoding.UTF8.GetBytes(password),
                salt);

            Console.WriteLine();
            Console.WriteLine("Hashed Password = " + Convert.ToBase64String(hashedPassword1));
            Console.WriteLine();
        }