public static byte[] Sha3256(byte[] bytes) { lock (sha3Lock) { return(sha3.ComputeHash(bytes)); } }
public static byte[] HashAndDispose(this SHA3 sha3, byte[] buffer) { var hash = sha3.ComputeHash(buffer); (sha3 as IDisposable).Dispose(); return(hash); }
static void Main() { var stopwatch = new Stopwatch(); byte[] data = { 0, 0, 5, 1, 1, 2 }; string word = "abc"; HashAlgorithm hash = new HashFunctions.SHA1(); stopwatch.Start(); Console.WriteLine($@"Proper HASH SHA1(data): {ByteArrayToString(hash.ComputeHash(data))}"); stopwatch.Stop(); Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s"); stopwatch.Reset(); stopwatch.Start(); Console.WriteLine($"Proper HASH SHA1 (word): {ByteArrayToString(hash.ComputeHash(Encoding.ASCII.GetBytes(word)))}"); stopwatch.Stop(); Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s"); Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks"); Console.WriteLine($"Speed of hashing: {Encoding.ASCII.GetBytes(word).Length * 1000000 / stopwatch.Elapsed.Ticks} bps"); SHA3 hash5 = new SHA3(256); stopwatch.Reset(); stopwatch.Start(); Console.WriteLine($"Proper HASH SHA3-512 (word): {ByteArrayToString(hash5.ComputeHash(Encoding.UTF8.GetBytes(word)))}"); stopwatch.Stop(); Console.WriteLine($"Data hashed in: {stopwatch.Elapsed} s"); Console.WriteLine($"Data hashed in: {stopwatch.ElapsedTicks} ticks"); Console.WriteLine($"Speed of hashing: {((double)(Encoding.ASCII.GetBytes(word).Length / 1024) * 1000L * 1000L * 10L / (stopwatch.ElapsedTicks)):f2} bps"); SHA2Managed hash6 = new SHA2Managed(512); stopwatch.Reset(); Console.WriteLine($"Proper HASH SHA-512(word): {ByteArrayToString(hash6.ComputeHash(Encoding.UTF8.GetBytes(word)))}"); SHA2Managed hash7 = new SHA2Managed(224); stopwatch.Reset(); Console.WriteLine($"Proper HASH SHA-224(word): {ByteArrayToString(hash7.ComputeHash(Encoding.UTF8.GetBytes(word)))}"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new HashFunctionAnalizerForm()); }
private string ComputeHash(SHA3 algorithm, string plainText) { return(Hash .FromBytes(algorithm.ComputeHash(plainText.ToByteArray())) .ToString()); }