internal static void GetHashBlock(byte[] input, ref SwrveABCDStruct ABCDValue, int ibStart) { uint[] array = SwrveMD5Core.Converter(input, ibStart); uint num = ABCDValue.A; uint num2 = ABCDValue.B; uint num3 = ABCDValue.C; uint num4 = ABCDValue.D; num = SwrveMD5Core.r1(num, num2, num3, num4, array[0], 7, 3614090360u); num4 = SwrveMD5Core.r1(num4, num, num2, num3, array[1], 12, 3905402710u); num3 = SwrveMD5Core.r1(num3, num4, num, num2, array[2], 17, 606105819u); um4 = SwrveMD5Core.r4(num4, num, num2, num3, array[7], 10, 1126891415u); num3 = SwrveMD5Core.r4(num3, num4, num, num2, array[14], 15, 2878612391u); num2 = SwrveMD5Core.r4(num2, num3, num4, num, array[5], 21, 4237533241u); num = SwrveMD5Core.r4(num, num2, num3, num4, array[12], 6, 1700485571u); num4 = SwrveMD5Core.r4(num4, num, num2, num3, array[3], 10, 2399980690u); num3 = SwrveMD5Core.r4(num3, num4, num, num2, array[10], 15, 4293915773u); num2 = SwrveMD5Core.r4(num2, num3, num4, num, array[1], 21, 2240044497u); num = SwrveMD5Core.r4(num, num2, num3, num4, array[8], 6, 1873313359u); num4 = SwrveMD5Core.r4(num4, num, num2, num3, array[15], 10, 4264355552u); num3 = SwrveMD5Core.r4(num3, num4, num, num2, array[6], 15, 2734768916u); num2 = SwrveMD5Core.r4(num2, num3, num4, num, array[13], 21, 1309151649u); num = SwrveMD5Core.r4(num, num2, num3, num4, array[4], 6, 4149444226u); num4 = SwrveMD5Core.r4(num4, num, num2, num3, array[11], 10, 3174756917u); num3 = SwrveMD5Core.r4(num3, num4, num, num2, array[2], 15, 718787259u); num2 = SwrveMD5Core.r4(num2, num3, num4, num, array[9], 21, 3951481745u); ABCDValue.A = num + ABCDValue.A; ABCDValue.B = num2 + ABCDValue.B; ABCDValue.C = num3 + ABCDValue.C; ABCDValue.D = num4 + ABCDValue.D; }
internal static byte[] GetHashFinalBlock(byte[] input, int ibStart, int cbSize, SwrveABCDStruct ABCD, long len) { byte[] array = new byte[64]; byte[] bytes = BitConverter.GetBytes(len); Array.Copy(input, ibStart, array, 0, cbSize); array[cbSize] = 128; if (cbSize < 56) { Array.Copy(bytes, 0, array, 56, 8); SwrveMD5Core.GetHashBlock(array, ref ABCD, 0); } else { SwrveMD5Core.GetHashBlock(array, ref ABCD, 0); array = new byte[64]; Array.Copy(bytes, 0, array, 56, 8); SwrveMD5Core.GetHashBlock(array, ref ABCD, 0); } byte[] array2 = new byte[16]; Array.Copy(BitConverter.GetBytes(ABCD.A), 0, array2, 0, 4); Array.Copy(BitConverter.GetBytes(ABCD.B), 0, array2, 4, 4); Array.Copy(BitConverter.GetBytes(ABCD.C), 0, array2, 8, 4); Array.Copy(BitConverter.GetBytes(ABCD.D), 0, array2, 12, 4); return(array2); }
public static byte[] GetHash(byte[] input) { if (null == input) { throw new System.ArgumentNullException("input", "Unable to calculate hash over null input data"); } //Intitial values defined in RFC 1321 SwrveABCDStruct abcd = new SwrveABCDStruct(); abcd.A = 0x67452301; abcd.B = 0xefcdab89; abcd.C = 0x98badcfe; abcd.D = 0x10325476; //We pass in the input array by block, the final block of data must be handled specialy for padding & length embeding int startIndex = 0; while (startIndex <= input.Length - 64) { SwrveMD5Core.GetHashBlock(input, ref abcd, startIndex); startIndex += 64; } // The final data block. return(SwrveMD5Core.GetHashFinalBlock(input, startIndex, input.Length - startIndex, abcd, (Int64)input.Length * 8)); }
public static string GetHashString(byte[] input) { if (input == null) { throw new ArgumentNullException("input", "Unable to calculate hash over null input data"); } string text = BitConverter.ToString(SwrveMD5Core.GetHash(input)); return(text.Replace("-", string.Empty)); }
public static byte[] GetHash(string input, Encoding encoding) { if (input == null) { throw new ArgumentNullException("input", "Unable to calculate hash over null input data"); } if (encoding == null) { throw new ArgumentNullException("encoding", "Unable to calculate hash over a string without a default encoding. Consider using the GetHash(string) overload to use UTF8 Encoding"); } byte[] bytes = encoding.GetBytes(input); return(SwrveMD5Core.GetHash(bytes)); }
public static byte[] GetHash(byte[] input) { if (input == null) { throw new ArgumentNullException("input", "Unable to calculate hash over null input data"); } SwrveABCDStruct aBCD = default(SwrveABCDStruct); aBCD.A = 1732584193u; aBCD.B = 4023233417u; aBCD.C = 2562383102u; aBCD.D = 271733878u; int i; for (i = 0; i <= input.Length - 64; i += 64) { SwrveMD5Core.GetHashBlock(input, ref aBCD, i); } return(SwrveMD5Core.GetHashFinalBlock(input, i, input.Length - i, aBCD, (long)input.Length * 8L)); }
public static string GetHashString(string input) { return(SwrveMD5Core.GetHashString(input, new UTF8Encoding())); }
public static byte[] GetHash(string input) { return(SwrveMD5Core.GetHash(input, new UTF8Encoding())); }
private static uint r4(uint a, uint b, uint c, uint d, uint x, int s, uint t) { return(b + SwrveMD5Core.LSR(a + (c ^ (b | (d ^ 4294967295u))) + x + t, s)); }
private static uint r3(uint a, uint b, uint c, uint d, uint x, int s, uint t) { return(b + SwrveMD5Core.LSR(a + (b ^ c ^ d) + x + t, s)); }
private static uint r2(uint a, uint b, uint c, uint d, uint x, int s, uint t) { return(b + SwrveMD5Core.LSR(a + ((b & d) | (c & (d ^ 4294967295u))) + x + t, s)); }
private static uint r1(uint a, uint b, uint c, uint d, uint x, int s, uint t) { return(b + SwrveMD5Core.LSR(a + ((b & c) | ((b ^ 4294967295u) & d)) + x + t, s)); }
public static byte[] MD5(String str) { byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(str); return(SwrveMD5Core.GetHash(inputBytes)); }
public static byte[] MD5(string str) { byte[] bytes = Encoding.UTF8.GetBytes(str); return(SwrveMD5Core.GetHash(bytes)); }