Exemplo n.º 1
0
        private static void Blake2Tests()
        {
            const string input = "ABCD";

            byte[] bytes = Encoding.UTF8.GetBytes(input);
            using ProtectedMemory protectedMemory = ProtectedMemory.Allocate(bytes.Length);
            protectedMemory.Write(bytes, 0);
            Blake2bProtectedCryptoProvider blake2 = new Blake2bProtectedCryptoProvider();

            Console.WriteLine(blake2.ComputeHash(protectedMemory));
        }
Exemplo n.º 2
0
        private static void Blake2PerfTest()
        {
            byte[] bytes = Encoding.UTF8.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
            using ProtectedMemory protectedMemory = ProtectedMemory.Allocate(bytes.Length);
            protectedMemory.Write(bytes, 0);
            Blake2bProtectedCryptoProvider blake2 = new Blake2bProtectedCryptoProvider();
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            for (int i = 0; i < 1000000; i++)
            {
                _ = blake2.ComputeHash(protectedMemory);
            }
            stopwatch.Stop();
            Console.WriteLine("1000000 hashes done in " + stopwatch.Elapsed.ToString());
            double t = stopwatch.ElapsedMilliseconds / 1000000d;

            Console.WriteLine(" * " + t.ToString() + " ms per digest.");
            Console.WriteLine(" * " + (1000d / t).ToString() + " hashes per second.");
        }