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
            ABCDStruct abcd = new ABCDStruct();

            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)
            {
                MD5Core.GetHashBlock(input, ref abcd, startIndex);
                startIndex += 64;
            }
            // The final data block.
            return(MD5Core.GetHashFinalBlock(input, startIndex, input.Length - startIndex, abcd, (Int64)input.Length * 8));
        }
Ejemplo n.º 2
0
        protected override void HashCore(byte[] array, int ibStart, int cbSize)
        {
            int num = _dataSize + cbSize;

            if (num >= 64)
            {
                Array.Copy(array, ibStart, _data, _dataSize, 64 - _dataSize);
                MD5Core.GetHashBlock(_data, ref _abcd, 0);
                int num2 = ibStart + (64 - _dataSize);
                num -= 64;
                while (num >= 64)
                {
                    Array.Copy(array, num2, _data, 0, 64);
                    MD5Core.GetHashBlock(array, ref _abcd, num2);
                    num  -= 64;
                    num2 += 64;
                }
                _dataSize = num;
                Array.Copy(array, num2, _data, 0, num);
            }
            else
            {
                Array.Copy(array, ibStart, _data, _dataSize, cbSize);
                _dataSize = num;
            }
            _totalLength += cbSize;
        }
Ejemplo n.º 3
0
        //protected override void HashCore(byte[] array, int ibStart, int cbSize)
        protected void HashCore(byte[] array, int ibStart, int cbSize)
        {
            int startIndex       = ibStart;
            int totalArrayLength = _dataSize + cbSize;

            if (totalArrayLength >= 64)
            {
                Array.Copy(array, startIndex, _data, _dataSize, 64 - _dataSize);
                // Process message of 64 bytes (512 bits)
                MD5Core.GetHashBlock(_data, ref _abcd, 0);
                startIndex       += 64 - _dataSize;
                totalArrayLength -= 64;
                while (totalArrayLength >= 64)
                {
                    Array.Copy(array, startIndex, _data, 0, 64);
                    MD5Core.GetHashBlock(array, ref _abcd, startIndex);
                    totalArrayLength -= 64;
                    startIndex       += 64;
                }
                _dataSize = totalArrayLength;
                Array.Copy(array, startIndex, _data, 0, totalArrayLength);
            }
            else
            {
                Array.Copy(array, startIndex, _data, _dataSize, cbSize);
                _dataSize = totalArrayLength;
            }
            _totalLength += cbSize;
        }
Ejemplo n.º 4
0
 protected override byte[] HashFinal()
 {
     HashValue = MD5Core.GetHashFinalBlock(_data, 0, _dataSize, _abcd, _totalLength * 8);
     return(HashValue);
 }
Ejemplo n.º 5
0
 //protected override byte[] HashFinal()
 protected byte[] HashFinal()
 {
     this.HashValue = MD5Core.GetHashFinalBlock(_data, 0, _dataSize, _abcd, _totalLength * 8);
     return(this.HashValue);
 }