/// <summary> /// Test the StreamDigest class implementation /// <para>Throws an Exception on failure</</para> /// </summary> public static void StreamDigestTest() { byte[] data; MemoryStream instrm; MemoryStream outstrm = new MemoryStream(); using (KeyGenerator kg = new KeyGenerator()) data = kg.GetBytes(512); // data to digest instrm = new MemoryStream(data); byte[] code1; byte[] code2; using (StreamDigest sd = new StreamDigest(Digests.Keccak512)) { sd.Initialize(instrm); code1 = sd.ComputeHash(); } using (Keccak512 kc = new Keccak512()) code2 = kc.ComputeHash(data); // compare the hash codes if (!Compare.AreEqual(code1, code2)) throw new Exception(); }
private byte[] HashTest2(string FileName) { using (FileStream inStream = new FileStream(FileName, FileMode.Open)) { using (StreamDigest dgst = new StreamDigest(new SHA512())) { dgst.Initialize(inStream); // linear processing dgst.IsConcurrent = false; return dgst.ComputeHash(); } } }
private bool HashTest3() { byte[] data = new CSPRng().GetBytes(33033); byte[] hash1; byte[] hash2; using (StreamDigest dgt1 = new StreamDigest(new SHA512())) { dgt1.Initialize(new MemoryStream(data)); // run concurrent mode dgt1.IsConcurrent = true; hash1 = dgt1.ComputeHash(); } using (SHA512 dgt2 = new SHA512()) hash2 = dgt2.ComputeHash(data); return Compare.AreEqual(hash1, hash2); }
private byte[] HashTest1(string FileName) { using (FileStream inStream = new FileStream(FileName, FileMode.Open)) { using (StreamDigest dgst = new StreamDigest(new SHA512())) { dgst.Initialize(inStream); // run concurrent mode dgst.IsConcurrent = true; return dgst.ComputeHash(); } } }