Пример #1
0
        private static void HashPassword(string passwordToHash, int numberOfRounds)
        {
            var sw = new Stopwatch();

            sw.Start();

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

            sw.Stop();

            Console.WriteLine();
            Console.WriteLine("Password to hash : " + passwordToHash);
            Console.WriteLine("Hashed Password : "******"Iterations <" + numberOfRounds + "> Elapsed Time : " + sw.ElapsedMilliseconds + "ms");
        }
Пример #2
0
        public static void Main()
        {
            // TODO : Calculate a PBKDF2 hash for a password but with different levels of difficulty.
            // TODO : Base64 the results and display on the console.

            // TODO : For bonus points, time the results of each difficulty level and print to the console.

            var inputMessage1            = "Hello, World!";
            var inputMessage1AsByteArray = Encoding.UTF8.GetBytes(inputMessage1);
            var salt = PBKDF2.GenerateSalt();

            for (int i = 0; i < 24; i++)
            {
                var stopWatch  = new Stopwatch();
                var iterations = 2 << i;

                stopWatch.Start();
                var result = PBKDF2.HashPassword(inputMessage1AsByteArray, salt, iterations);
                stopWatch.Stop();

                Console.WriteLine($"Hashing '{inputMessage1}' took {stopWatch.ElapsedMilliseconds}ms with {iterations} iterations, result = {Convert.ToBase64String( result)}");
            }
        }