public virtual ITestResult Perform() { IDigest digest = new RipeMD256Digest(); byte[] resBuf = new byte[digest.GetDigestSize()]; for (int i = 0; i < messages.Length; i++) { byte[] m = Encoding.ASCII.GetBytes(messages[i]); digest.BlockUpdate(m, 0, m.Length); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[i]))) { return(new SimpleTestResult(false, Name + ": Vector " + i + " failed" + " expected: " + digests[i] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } } // // test 2 // byte[] m2 = Encoding.ASCII.GetBytes(messages[messages.Length - 1]); digest.BlockUpdate(m2, 0, m2.Length / 2); // clone the IDigest IDigest d = new RipeMD256Digest((RipeMD256Digest)digest); digest.BlockUpdate(m2, m2.Length / 2, m2.Length - m2.Length / 2); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD256 failing clone test" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } d.BlockUpdate(m2, m2.Length / 2, m2.Length - m2.Length / 2); d.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD256 failing clone test - part 2" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } for (int i = 0; i < 1000000; i++) { digest.Update((byte)'a'); } digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(MillionADigest))) { return(new SimpleTestResult(false, Name + ": Million a's failed")); } return(new SimpleTestResult(true, Name + ": Okay")); }
public static byte[] Hash256(byte[] bytes) { var digest = new RipeMD256Digest(); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(bytes, 0, bytes.Length); digest.DoFinal(output, 0); return(output); }
public static byte[] Hash256(byte[] message) { var digest = new RipeMD256Digest(); var output = new byte[digest.GetDigestSize()]; byte[] msg = message ?? new byte[0]; digest.BlockUpdate(msg, 0, msg.Length); digest.DoFinal(output, 0); return(output); }