/// <summary> /// Test the DigestStream 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 (DigestStream sd = new DigestStream(Digests.Keccak512)) { sd.Initialize(instrm); code1 = sd.ComputeHash(); } using (Keccak512 kc = new Keccak512()) code2 = kc.ComputeHash(data); // compare the hash codes if (!Evaluate.AreEqual(code1, code2)) { throw new Exception(); } }
private byte[] HashTest2(string FileName) { using (FileStream inStream = new FileStream(FileName, FileMode.Open)) { using (DigestStream dgst = new DigestStream(new SHA512())) { dgst.Initialize(inStream); // linear processing dgst.IsConcurrent = false; return(dgst.ComputeHash()); } } }
private byte[] HashTest1(string FileName) { using (FileStream inStream = new FileStream(FileName, FileMode.Open)) { using (DigestStream dgst = new DigestStream(new SHA512())) { dgst.Initialize(inStream); // run concurrent mode dgst.IsConcurrent = true; return(dgst.ComputeHash()); } } }
private bool HashTest3() { byte[] data = new CSPPrng().GetBytes(33033); byte[] hash1; byte[] hash2; using (DigestStream dgt1 = new DigestStream(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(Evaluate.AreEqual(hash1, hash2)); }