MD2/MD4 Example
[Hashing Home][Home]
The MD2 and MD4 hashing functions were developed by Prof Ronald Rivest in 1989 and 1990, respectively. They both produce a 128-bit hash, but have been shown be vulnerable to attack (see the Collision section below). [Theory]
The results are then:
|
Examples
- Try "The quick brown fox jumps over the lazy dog". Try!, which should give a MD2 hash of: 03d85a0d629d2c442e987525319fc471 Check
- Try "". Try!, which should give a MD4 hash of: 31d6cfe0d16ae931b73c59d7e0c089c0 Check
- Try "Test vector from febooti.com". Try!, which should give a MD4 hash of: 6578f2664bc56e0b5b3f85ed26ecc67b Check
- Try "a". Try!, which should give a MD4 hash of: bde52cb31de33e46245e05fbdbd6fb24 Check
- Try "message digest". Try!, which should give a MD4 hash of: d9130a8164549fe818874806e1c7014b Check
Collision
A collision occurs when two different inputs produce the same hash signature. The following shows two examples where two different input values produce the same hash signature. The differences between the two values is defined in bold. In this case the characters produced by the data are non-printing ones, so the data is defined as a hex string (which is converted into a byte array based on the hex values). With this a hex value is used to represent the data (if you want to try put a 0x in front of the data and pass into this Web page):
- Try "839c7a4d7a92cb5678a5d5b9eea5a7573c8a74deb366c3dc20a083b69f5d2a3bb3719dc69891e9f95e809fd7e8b23ba6318edd45e51fe39708bf9427e9c3e8b9". Try!, which should give a MD4 hash of: 4d7e6a1defa93d2dde05b45d864c429b Check
- Try "839c7a4d7a92cbd678a5d529eea5a7573c8a74deb366c3dc20a083b69f5d2a3bb3719dc69891e9f95e809fd7e8b23ba6318edc45e51fe39708bf9427e9c3e8b9". Try!, which should give a MD4 hash of: 4d7e6a1defa93d2dde05b45d864c429b Check
- Try "839c7a4d7a92cb5678a5d5b9eea5a7573c8a74deb366c3dc20a083b69f5d2a3bb3719dc69891e9f95e809fd7e8b23ba6318edd45e51fe39740c213f769cfb8a7". Try!, which should give a MD4 hash of: c6f3b3fe1f4833e0697340fb214fb9ea Check
- Try "839c7a4d7a92cbd678a5d529eea5a7573c8a74deb366c3dc20a083b69f5d2a3bb3719dc69891e9f95e809fd7e8b23ba6318edc45e51fe39740c213f769cfb8a7". Try!, which should give a MD4 hash of: c6f3b3fe1f4833e0697340fb214fb9ea Check
NTLM Hash
MD4 is used with the Microsoft NTLM hash. Basically we take the string and convert it to a Little Endian Unicode string (basically added a zero value byte after each character. If you want to try, use the Little Endian Unicode option with "hello" and you should get "066DDFD4EF0E9CD7C256FE77191EF43C" [LM/NTLM]
Presentation
Sample code
using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; using Org.BouncyCastle.Crypto.Paddings; public void checkMD(string message, bool hex) { byte[] data = null; byte[] o = null; if (message == null) return; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); if (hex == false) data = encoding.GetBytes(message); else data = StringToByteArray(message); Org.BouncyCastle.Crypto.Digests.MD2Digest w4 = new Org.BouncyCastle.Crypto.Digests.MD2Digest(); w4.Reset(); w4.BlockUpdate(data, 0, data.Length); o = new byte[w4.GetDigestSize()]; w4.DoFinal(o, 0); md2 = Global.ByteToString(o); Org.BouncyCastle.Crypto.Digests.MD4Digest w5 = new Org.BouncyCastle.Crypto.Digests.MD4Digest(); w5.Reset(); w5.BlockUpdate(data, 0, data.Length); o = new byte[w5.GetDigestSize()]; w5.DoFinal(o, 0); md4 = Global.ByteToString(o); Org.BouncyCastle.Crypto.Digests.NullDigest w6 = new Org.BouncyCastle.Crypto.Digests.NullDigest(); w6.Reset(); w6.BlockUpdate(data, 0, data.Length); o = new byte[w6.GetDigestSize()]; w6.DoFinal(o, 0); nullhash = Global.ByteToString(o); }