public void ComputeHash_ReuseTest() { // From https://en.wikipedia.org/wiki/RIPEMD#RIPEMD-160_hashes byte[] msg1 = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy dog"); byte[] msg2 = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy cog"); byte[] exp1 = Helper.HexToBytes("37f332f68db77bd9d7edd4969571ad671cf9dd3b"); byte[] exp2 = Helper.HexToBytes("132072df690933835eb8b6ad0b77e7b6f14acad7"); using Ripemd160 rip = new Ripemd160(); byte[] act1 = rip.ComputeHash(msg1); byte[] act2 = rip.ComputeHash(msg2); Assert.Equal(exp1, act1); Assert.Equal(exp2, act2); }
public void ComputeHash_AMillionATest() { using Ripemd160 rip = new Ripemd160(); byte[] actualHash = rip.ComputeHash(HashTestCaseHelper.GetAMillionA()); byte[] expectedHash = Helper.HexToBytes("52783243c1697bdbe16d37f97f68f08325dc1528"); Assert.Equal(expectedHash, actualHash); }
public void ComputeHash_DoubleTest() { using Ripemd160 rip = new Ripemd160(true); byte[] data = Helper.HexToBytes("fb8049137747e712628240cf6d7056ea2870170cb7d9bc713d91e901b514c6ae7d7dda3cd03ea1b99cf85046a505f3590541123d3f8f2c22c4d7d6e65de65c4ebb9251f09619"); byte[] actualHash = rip.ComputeHash(data); byte[] expectedHash = Helper.HexToBytes("dd0ea2c8b8f2fba4e1a1b58080fb59b0350c7aba"); Assert.Equal(expectedHash, actualHash); }
public void ComputeHash_WithIndexTest() { using Ripemd160 rip = new Ripemd160(); byte[] data = Helper.HexToBytes("123fab54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f67f3a25c92"); byte[] actualHash = rip.ComputeHash(data, 3, 43); byte[] expectedHash = Helper.HexToBytes("37f332f68db77bd9d7edd4969571ad671cf9dd3b"); Assert.Equal(expectedHash, actualHash); }
/// <summary> /// Replaces top stack item with its hash digest. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = Err.OpNotEnoughItems; return(false); } using Ripemd160 hash = new Ripemd160(); opData.Push(hash.ComputeHash(opData.Pop())); error = null; return(true); }
public void ComputeHash_ExceptionsTest() { byte[] goodBa = { 1, 2, 3 }; Ripemd160 rip = new Ripemd160(); Assert.Throws <ArgumentNullException>(() => rip.ComputeHash(null)); Assert.Throws <ArgumentNullException>(() => rip.ComputeHash(null, 0, 1)); Assert.Throws <IndexOutOfRangeException>(() => rip.ComputeHash(goodBa, 0, 5)); Assert.Throws <IndexOutOfRangeException>(() => rip.ComputeHash(goodBa, 10, 1)); rip.Dispose(); Assert.Throws <ObjectDisposedException>(() => rip.ComputeHash(goodBa)); Assert.Throws <ObjectDisposedException>(() => rip.ComputeHash(goodBa, 0, 2)); }
public void ComputeHash_ProgressiveTest(byte[] message, byte[] expectedHash) { using Ripemd160 rip = new Ripemd160(); byte[] actualHash = rip.ComputeHash(message); Assert.Equal(expectedHash, actualHash); }
private byte[] ComputeHash160(byte[] data) { using var sha = System.Security.Cryptography.SHA256.Create(); using var rip = new Ripemd160(); return(rip.ComputeHash(sha.ComputeHash(data))); }