/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ private static void MD5Update(MD5_CTX context, /* context */ byte[] input, /* input block */ uint inputIndex, // Starting index for input block uint inputLen) /* length of input block */ { /* Compute number of bytes mod 64 */ uint index = (uint)((context.count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context.count[0] += ((uint)inputLen << 3)) < ((uint)inputLen << 3)) { context.count[1]++; } context.count[1] += ((uint)inputLen >> 29); uint partLen = 64 - index; /* Transform as many times as possible. */ uint i = 0; if (inputLen >= partLen) { Buffer.BlockCopy(input, (int)inputIndex, context.buffer, (int)index, (int)partLen); MD5Transform(context.state, context.buffer, 0); for (i = partLen; i + 63 < inputLen; i += 64) { MD5Transform(context.state, input, inputIndex + i); } index = 0; } /* Buffer remaining input */ Buffer.BlockCopy(input, (int)(inputIndex + i), context.buffer, (int)index, (int)(inputLen - i)); }
private static void MD5Init(MD5_CTX context) { context.count[0] = (context.count[1] = 0u); context.state[0] = 1732584193u; context.state[1] = 4023233417u; context.state[2] = 2562383102u; context.state[3] = 271733878u; }
/// <summary> /// Init /// </summary> private myMD5() { context = new MD5_CTX(); context.count[0] = context.count[1] = 0; context.state[0] = 0x67452301; /*word A: 01 23 45 67*/ context.state[1] = 0xefcdab89; /*word B: 89 ab cd ef*/ context.state[2] = 0x98badcfe; /*word C: fe dc ba 98*/ context.state[3] = 0x10325476; /*word D: 76 54 32 10*/ }
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ private static void MD5Init(MD5_CTX context) /* context */ { context.Count[0] = context.Count[1] = 0; /* Load magic initialization constants. */ context.State[0] = 0x67452301; context.State[1] = 0xefcdab89; context.State[2] = 0x98badcfe; context.State[3] = 0x10325476; }
/* MD5 initialization. Begins an MD5 operation, writing a new context. */ private static void MD5Init(MD5_CTX context) /* context */ { context.count[0] = context.count[1] = 0; /* Load magic initialization constants. */ context.state[0] = new Vector4ui(H0); context.state[1] = new Vector4ui(H1); context.state[2] = new Vector4ui(H2); context.state[3] = new Vector4ui(H3); }
public static Byte[] MD5Hex(Byte[] str) { MD5_CTX ctx = new MD5_CTX(); Int32 len = str.Length; MD5Init(ref ctx); MD5Update(ref ctx, str, len); MD5Final(ref ctx); return(ctx.digest); }
public static Byte[] MD5Encrypt(Byte[] str) { MD5_CTX ctx = new MD5_CTX(); Int32 len = str.Length; MD5Init(ref ctx); MD5Update(ref ctx, str, len); MD5Final(ref ctx); return(Hex2ASC(ctx.digest, 16)); }
private static void MD5Final(byte[] digest, MD5_CTX context) { byte[] array = new byte[8]; Encode(array, context.count, 8u); uint num = (context.count[0] >> 3) & 0x3F; uint inputLen = (num < 56) ? (56 - num) : (120 - num); MD5Update(context, PADDING, 0u, inputLen); MD5Update(context, array, 0u, 8u); Encode(digest, context.state, 16u); context.Clear(); }
/* MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ private static void MD5Final(byte[] digest, /* message digest */ MD5_CTX context) /* context */ { byte[] bits = new byte[8]; /* Save number of bits */ Encode(bits, context.count, 8); /* Pad out to 56 mod 64. */ uint index = (uint)((context.count[0] >> 3) & 0x3f); uint padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update(context, PADDING, 0, padLen); /* Append length (before padding) */ MD5Update(context, bits, 0, 8); /* Store state in digest */ Encode(digest, context.state, 16); /* Zeroize sensitive information. */ context.Clear(); }
/* MD5 block update operation. Continues an MD5 message-digest * operation, processing another message block, and updating the * context. */ private static void MD5Update(MD5_CTX context, /* context */ byte[] input, /* input block */ uint inputIndex, // Starting index for input block uint inputLen) /* length of input block */ { /* Compute number of bytes mod 64 */ uint index = (uint)((context.count[0] >> 3) & 0x3F); /* Update number of bits */ if ((context.count[0] += ((uint)inputLen << 3)) < ((uint)inputLen << 3)) { context.count[1]++; } context.count[1] += ((uint)inputLen >> 29); uint partLen = 64 - index; /* Transform as many times as possible. */ uint i = 0; if (inputLen >= partLen) { System.Runtime.CompilerServices.Unsafe .CopyBlockUnaligned(ref context.buffer[(int)index], ref input[(int)inputIndex], partLen); MD5Transform(context.state, context.buffer, 0); for (i = partLen; i + 63 < inputLen; i += 64) { MD5Transform(context.state, input, inputIndex + i); } index = 0; } /* Memory remaining input */ System.Runtime.CompilerServices.Unsafe .CopyBlockUnaligned(ref context.buffer[(int)index], ref input[(int)(inputIndex + i)], (inputLen - i)); }
private static void MD5Update(MD5_CTX context, byte[] input, uint inputIndex, uint inputLen) { uint num = (context.count[0] >> 3) & 0x3F; if ((context.count[0] += inputLen << 3) < inputLen << 3) { context.count[1]++; } context.count[1] += inputLen >> 29; uint num2 = 64 - num; uint num3 = 0u; if (inputLen >= num2) { Buffer.BlockCopy(input, (int)inputIndex, context.buffer, (int)num, (int)num2); MD5Transform(context.state, context.buffer, 0u); for (num3 = num2; num3 + 63 < inputLen; num3 += 64) { MD5Transform(context.state, input, inputIndex + num3); } num = 0u; } Buffer.BlockCopy(input, (int)(inputIndex + num3), context.buffer, (int)num, (int)(inputLen - num3)); }
/* MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context. */ private static void MD5Final(byte[] digest, /* message digest */ MD5_CTX context) /* context */ { byte[] bits = new byte[8]; /* Save number of bits */ Encode(bits, context.Count, 8); /* Pad out to 56 mod 64. */ uint index = (context.Count[0] >> 3) & 0x3f; uint padLen = (index < 56) ? (56 - index) : (120 - index); MD5Update(context, PADDING, 0, padLen); /* Append length (before padding) */ MD5Update(context, bits, 0, 8); /* Store state in digest */ Encode(digest, context.State, 16); /* Zeroize sensitive information. */ context.Clear(); }
/* MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context. */ private static void MD5Update(MD5_CTX context, /* context */ byte[] input, /* input block */ uint inputIndex, // Starting index for input block uint inputLen) /* length of input block */ { /* Compute number of bytes mod 64 */ uint index = (context.Count[0] >> 3) & 0x3F; /* Update number of bits */ if ((context.Count[0] += (inputLen << 3)) < (inputLen << 3)) { context.Count[1]++; } context.Count[1] += (inputLen >> 29); uint partLen = 64 - index; /* Transform as many times as possible. */ uint i = 0; if (inputLen >= partLen) { Buffer.BlockCopy(input, (int)inputIndex, context.Buffer, (int)index, (int)partLen); MD5Transform(context.State, context.Buffer, 0); for (i = partLen; i + 63 < inputLen; i += 64) { MD5Transform(context.State, input, inputIndex + i); } index = 0; } /* Buffer remaining input */ Buffer.BlockCopy(input, (int)(inputIndex + i), context.Buffer, (int)index, (int)(inputLen - i)); }
public static extern void MD5Final(ref MD5_CTX context);
public static extern void MD5Update(ref MD5_CTX context, Byte[] input, Int32 inlen);
public static extern void MD5Init(ref MD5_CTX context);