public static byte[] Hash128(byte[] bytes)
        {
            var digest = new RipeMD128Digest();
            var output = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(bytes, 0, bytes.Length);
            digest.DoFinal(output, 0);
            return(output);
        }
Exemple #2
0
        public static byte[] Hash128(byte[] message)
        {
            var digest = new RipeMD128Digest();
            var output = new byte[digest.GetDigestSize()];

            byte[] msg = message ?? new byte[0];
            digest.BlockUpdate(msg, 0, msg.Length);
            digest.DoFinal(output, 0);
            return(output);
        }
Exemple #3
0
        public ITestResult Perform()
        {
            IDigest digest = new RipeMD128Digest();

            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"));
                }
            }

            //
            // test 2
            //
            byte[] mm = Encoding.ASCII.GetBytes(messages[messages.Length - 1]);

            digest.BlockUpdate(mm, 0, mm.Length / 2);

            // clone the IDigest
            IDigest d = new RipeMD128Digest((RipeMD128Digest)digest);

            digest.BlockUpdate(mm, mm.Length / 2, mm.Length - mm.Length / 2);
            digest.DoFinal(resBuf, 0);

            if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1])))
            {
                return(new SimpleTestResult(false,
                                            "RipeMD128 failing clone test"
                                            + SimpleTest.NewLine
                                            + "    expected: " + digests[digests.Length - 1]
                                            + SimpleTest.NewLine
                                            + "    got     : " + Hex.ToHexString(resBuf)));
            }

            d.BlockUpdate(mm, mm.Length / 2, mm.Length - mm.Length / 2);
            d.DoFinal(resBuf, 0);

            if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1])))
            {
                return(new SimpleTestResult(false,
                                            "RipeMD128 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"));
        }