private static void ScryptTests() { // Iterations: 65536 // blockSize: 8 // Threads: 1 // SALT: TB5ny6LI9KywU3+TD5FdrNSsxYV2T+3qyxRwMieu7zQ= // HASH: +jsi778vVLkfYWp3dQDwW7g9/XMySal9lDoEQxvB6uc= byte[] bytes = Encoding.UTF8.GetBytes("ABCD"); ProtectedMemory protectedMemory = ProtectedMemory.Allocate(bytes.Length); protectedMemory.Write(bytes, 0); // ScryptProtectedCryptoProvider scryptProtected2 = new ScryptProtectedCryptoProvider(); // Console.WriteLine(scryptProtected2.ComputeHash(protectedMemory, Convert.FromBase64String("TB5ny6LI9KywU3+TD5FdrNSsxYV2T+3qyxRwMieu7zQ="), 65536, 8, 1, 32)); byte[] bytes2 = Encoding.UTF8.GetBytes("DCBA"); ProtectedMemory protectedMemory2 = ProtectedMemory.Allocate(bytes.Length); protectedMemory2.Write(bytes2, 0); ScryptProtectedCryptoProvider scryptProtected = new ScryptProtectedCryptoProvider(); string result = scryptProtected.ComputeHash(protectedMemory); Console.WriteLine(result); Console.WriteLine("Should be False:"); Console.WriteLine(scryptProtected.Compare(protectedMemory2, result)); Console.WriteLine("Should be True:"); Console.WriteLine(scryptProtected.Compare(protectedMemory, result)); }
private static void ScryptPerfTest() { byte[] bytes = Encoding.UTF8.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); using ProtectedMemory protectedMemory = ProtectedMemory.Allocate(bytes.Length); protectedMemory.Write(bytes, 0); ScryptProtectedCryptoProvider scryptProtected = new ScryptProtectedCryptoProvider(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int i = 0; i < 20; i++) { _ = scryptProtected.ComputeHash(protectedMemory); } stopwatch.Stop(); Console.WriteLine("20 hashes done in " + stopwatch.Elapsed.ToString()); double t = stopwatch.ElapsedMilliseconds / 20d; Console.WriteLine(" * " + t.ToString() + " ms per digest."); Console.WriteLine(" * " + (1000d / t).ToString() + " hashes per second."); }