public void ComputeHash_CreateMD5HashAndCompare_EqualHashPass() { GenericHasher<MD5CryptoServiceProvider> hasher = new GenericHasher<MD5CryptoServiceProvider>(); string stringToHash = "This is my hashable stuff"; byte[] hash = hasher.ComputeHash(stringToHash); byte[] md5hash = new MD5CryptoServiceProvider().ComputeHash(hasher.Encoding.GetBytes(stringToHash)); Assert.IsTrue(hasher.AreHashesEqual(hash, md5hash)); }
public void ComputeHash_HashValueFiveTimesAndCompareToNative_Pass() { GenericHasher<SHA256Managed> hasher = new GenericHasher<SHA256Managed>(); hasher.Encoding = Encoding.UTF8; string stringA = "welcoMe"; byte[] bytesToHash = hasher.Encoding.GetBytes(stringA); int iterationCount = 5; byte[] hash = null; byte[] compareHash = hasher.Encoding.GetBytes(stringA); // Our method hash = hasher.ComputeHash(bytesToHash, iterationCount); // native using(var digester = new SHA256Managed()) { for (int i = 0; i < 5; i++) compareHash = digester.ComputeHash(compareHash); } CollectionAssert.AreEqual(compareHash, hash); }