public void TestHash() { var input = Encoding.ASCII.GetBytes("hi, how are you?"); if (!string.Equals( Symmetric.Hash(input, 32).ToHexString(), "eda8506c1fb0bbcc3f62626fef074bbf2d09a8c7c608f3fa1482c9a625d00f75", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Hash does not produce a correct output"); } }
public void TestSum() { var message1 = Encoding.ASCII.GetBytes("hello"); var message2 = Encoding.ASCII.GetBytes("how are you good sir?"); var message3 = Encoding.ASCII.GetBytes("sure thing"); var fullMessage = message1.Concat(message2).ToArray(); // Trying with NewHash with streaming and without streaming var h1 = new Hash(32); h1.Write(message1); h1.Write(message2); var out1 = h1.Sum(); var h2 = new Hash(32); h2.Write(fullMessage); var out2 = h2.Sum(); if (!out1.SequenceEqual(out2)) { throw new Exception("Sum function does not work"); } // Trying with Hash() var out3 = Symmetric.Hash(fullMessage, 32); if (!out1.SequenceEqual(out3)) { throw new Exception("Sum function does not work"); } // Trying the streaming even more h1.Write(message3); out1 = h1.Sum(); h2.Write(message3); out2 = h2.Sum(); if (!out1.SequenceEqual(out2)) { throw new Exception("Sum function does not work"); } // tring with Hash() out3 = Symmetric.Hash(fullMessage.Concat(message3).ToArray(), 32); if (!out1.SequenceEqual(out3)) { throw new Exception("Sum function does not work"); } }