public static byte[] process(byte[] secretKey, byte[] data, int length)
        {
            SHA1HashFunction sha  = new SHA1HashFunction();
            SHA1HashFunction sha2 = new SHA1HashFunction();

            byte[] buffer   = new byte[SHA1HashFunction.HashSize];
            byte[] buffer2  = new byte[SHA1HashFunction.HashSize];
            int    arg_28_0 = SHA1HashFunction.HashSize;

            byte[] buffer3  = new byte[SHA1HashFunction.BlockSize];
            int    hashSize = secretKey.Length;

            if (hashSize > SHA1HashFunction.BlockSize)
            {
                SHA1HashFunction sha3 = new SHA1HashFunction();
                sha3.Reset();
                sha3.Input(secretKey);
                secretKey = sha3.Result();
                hashSize  = SHA1HashFunction.HashSize;
            }
            sha.Reset();
            for (int num = 0; num < hashSize; num++)
            {
                buffer3[num] = (byte)(secretKey[num] ^ 54);
            }
            for (int num = hashSize; num < SHA1HashFunction.BlockSize; num++)
            {
                buffer3[num] = 54;
            }
            sha.Input(buffer3);
            sha.Input(data);
            buffer = sha.Result();
            sha2.Reset();
            for (int num = 0; num < hashSize; num++)
            {
                buffer3[num] = (byte)(secretKey[num] ^ 92);
            }
            for (int num = hashSize; num < SHA1HashFunction.BlockSize; num++)
            {
                buffer3[num] = 92;
            }
            sha2.Input(buffer3);
            sha2.Input(buffer);
            buffer2 = sha2.Result();
            length  = ((length > SHA1HashFunction.HashSize) ? SHA1HashFunction.HashSize : length);
            byte[] buffer4 = new byte[length];
            CryptoEngineHMACSHA1.truncate(buffer2, buffer4, length);
            return(buffer4);
        }
示例#2
0
        /// <summary>
        /// </summary>
        /// <param name="secretKey"></param>
        /// <param name="data"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static byte[] process(byte[] secretKey, byte[] data, int length)
        {
            int num;
            SHA1HashFunction sha  = new SHA1HashFunction();
            SHA1HashFunction sha2 = new SHA1HashFunction();

            byte[] buffer   = new byte[SHA1HashFunction.HashSize];
            byte[] buffer2  = new byte[SHA1HashFunction.HashSize];
            byte[] buffer3  = new byte[SHA1HashFunction.HashSize];
            byte[] buffer4  = new byte[SHA1HashFunction.BlockSize];
            int    hashSize = secretKey.Length;

            if (hashSize > SHA1HashFunction.BlockSize)
            {
                SHA1HashFunction sha3 = new SHA1HashFunction();
                sha3.Reset();
                sha3.Input(secretKey);
                secretKey = sha3.Result();
                hashSize  = SHA1HashFunction.HashSize;
            }
            sha.Reset();
            for (num = 0; num < hashSize; num++)
            {
                buffer4[num] = (byte)(secretKey[num] ^ 0x36);
            }
            for (num = hashSize; num < SHA1HashFunction.BlockSize; num++)
            {
                buffer4[num] = 0x36;
            }
            sha.Input(buffer4);
            sha.Input(data);
            buffer = sha.Result();
            sha2.Reset();
            for (num = 0; num < hashSize; num++)
            {
                buffer4[num] = (byte)(secretKey[num] ^ 0x5c);
            }
            for (num = hashSize; num < SHA1HashFunction.BlockSize; num++)
            {
                buffer4[num] = 0x5c;
            }
            sha2.Input(buffer4);
            sha2.Input(buffer);
            buffer2 = sha2.Result();
            length  = (length > SHA1HashFunction.HashSize) ? SHA1HashFunction.HashSize : length;
            byte[] buffer5 = new byte[length];
            truncate(buffer2, buffer5, length);
            return(buffer5);
        }
 /// <summary>
 /// </summary>
 /// <param name="secretKey"></param>
 /// <param name="data"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public static byte[] process(byte[] secretKey, byte[] data, int length)
 {
     int num;
     SHA1HashFunction sha = new SHA1HashFunction();
     SHA1HashFunction sha2 = new SHA1HashFunction();
     byte[] buffer = new byte[SHA1HashFunction.HashSize];
     byte[] buffer2 = new byte[SHA1HashFunction.HashSize];
     byte[] buffer3 = new byte[SHA1HashFunction.HashSize];
     byte[] buffer4 = new byte[SHA1HashFunction.BlockSize];
     int hashSize = secretKey.Length;
     if (hashSize > SHA1HashFunction.BlockSize)
     {
         SHA1HashFunction sha3 = new SHA1HashFunction();
         sha3.Reset();
         sha3.Input(secretKey);
         secretKey = sha3.Result();
         hashSize = SHA1HashFunction.HashSize;
     }
     sha.Reset();
     for (num = 0; num < hashSize; num++)
     {
         buffer4[num] = (byte)(secretKey[num] ^ 0x36);
     }
     for (num = hashSize; num < SHA1HashFunction.BlockSize; num++)
     {
         buffer4[num] = 0x36;
     }
     sha.Input(buffer4);
     sha.Input(data);
     buffer = sha.Result();
     sha2.Reset();
     for (num = 0; num < hashSize; num++)
     {
         buffer4[num] = (byte)(secretKey[num] ^ 0x5c);
     }
     for (num = hashSize; num < SHA1HashFunction.BlockSize; num++)
     {
         buffer4[num] = 0x5c;
     }
     sha2.Input(buffer4);
     sha2.Input(buffer);
     buffer2 = sha2.Result();
     length = (length > SHA1HashFunction.HashSize) ? SHA1HashFunction.HashSize : length;
     byte[] buffer5 = new byte[length];
     truncate(buffer2, buffer5, length);
     return buffer5;
 }
		public static byte[] process(byte[] secretKey, byte[] data, int length)
		{
			SHA1HashFunction sha = new SHA1HashFunction();
			SHA1HashFunction sha2 = new SHA1HashFunction();
			byte[] buffer = new byte[SHA1HashFunction.HashSize];
			byte[] buffer2 = new byte[SHA1HashFunction.HashSize];
			int arg_28_0 = SHA1HashFunction.HashSize;
			byte[] buffer3 = new byte[SHA1HashFunction.BlockSize];
			int hashSize = secretKey.Length;
			if (hashSize > SHA1HashFunction.BlockSize)
			{
				SHA1HashFunction sha3 = new SHA1HashFunction();
				sha3.Reset();
				sha3.Input(secretKey);
				secretKey = sha3.Result();
				hashSize = SHA1HashFunction.HashSize;
			}
			sha.Reset();
			for (int num = 0; num < hashSize; num++)
			{
				buffer3[num] = (byte)(secretKey[num] ^ 54);
			}
			for (int num = hashSize; num < SHA1HashFunction.BlockSize; num++)
			{
				buffer3[num] = 54;
			}
			sha.Input(buffer3);
			sha.Input(data);
			buffer = sha.Result();
			sha2.Reset();
			for (int num = 0; num < hashSize; num++)
			{
				buffer3[num] = (byte)(secretKey[num] ^ 92);
			}
			for (int num = hashSize; num < SHA1HashFunction.BlockSize; num++)
			{
				buffer3[num] = 92;
			}
			sha2.Input(buffer3);
			sha2.Input(buffer);
			buffer2 = sha2.Result();
			length = ((length > SHA1HashFunction.HashSize) ? SHA1HashFunction.HashSize : length);
			byte[] buffer4 = new byte[length];
			CryptoEngineHMACSHA1.truncate(buffer2, buffer4, length);
			return buffer4;
		}
        private void ProcessMessageBlock()
        {
            uint[] numArray = new uint[]
            {
                1518500249u,
                1859775393u,
                2400959708u,
                3395469782u
            };
            uint[] numArray2 = new uint[80];
            for (int num = 0; num < 16; num++)
            {
                numArray2[num]  = (uint)((uint)this.Message_Block[num * 4] << 24);
                numArray2[num] |= (uint)((uint)this.Message_Block[num * 4 + 1] << 16);
                numArray2[num] |= (uint)((uint)this.Message_Block[num * 4 + 2] << 8);
                numArray2[num] |= (uint)this.Message_Block[num * 4 + 3];
            }
            for (int num = 16; num < 80; num++)
            {
                numArray2[num] = SHA1HashFunction.CircularShift(1, numArray2[num - 3] ^ numArray2[num - 8] ^ numArray2[num - 14] ^ numArray2[num - 16]);
            }
            uint word = this.Intermediate_Hash[0];
            uint num2 = this.Intermediate_Hash[1];
            uint num3 = this.Intermediate_Hash[2];
            uint num4 = this.Intermediate_Hash[3];
            uint num5 = this.Intermediate_Hash[4];

            for (int num = 0; num < 20; num++)
            {
                uint num6 = SHA1HashFunction.CircularShift(5, word) + ((num2 & num3) | (~num2 & num4)) + num5 + numArray2[num] + numArray[0];
                num5 = num4;
                num4 = num3;
                num3 = SHA1HashFunction.CircularShift(30, num2);
                num2 = word;
                word = num6;
            }
            for (int num = 20; num < 40; num++)
            {
                uint num6 = SHA1HashFunction.CircularShift(5, word) + (num2 ^ num3 ^ num4) + num5 + numArray2[num] + numArray[1];
                num5 = num4;
                num4 = num3;
                num3 = SHA1HashFunction.CircularShift(30, num2);
                num2 = word;
                word = num6;
            }
            for (int num = 40; num < 60; num++)
            {
                uint num6 = SHA1HashFunction.CircularShift(5, word) + ((num2 & num3) | (num2 & num4) | (num3 & num4)) + num5 + numArray2[num] + numArray[2];
                num5 = num4;
                num4 = num3;
                num3 = SHA1HashFunction.CircularShift(30, num2);
                num2 = word;
                word = num6;
            }
            for (int num = 60; num < 80; num++)
            {
                uint num6 = SHA1HashFunction.CircularShift(5, word) + (num2 ^ num3 ^ num4) + num5 + numArray2[num] + numArray[3];
                num5 = num4;
                num4 = num3;
                num3 = SHA1HashFunction.CircularShift(30, num2);
                num2 = word;
                word = num6;
            }
            this.Intermediate_Hash[0] += word;
            this.Intermediate_Hash[1] += num2;
            this.Intermediate_Hash[2] += num3;
            this.Intermediate_Hash[3] += num4;
            this.Intermediate_Hash[4] += num5;
            this.Message_Block_Index   = 0;
        }