Example #1
0
        public static byte[] DoubleHashData(byte[] data,
                                            uint clientToken, uint serverToken)
        {
            MemoryStream ms = new MemoryStream(28);
            BinaryWriter bw = new BinaryWriter(ms);

            byte[] firstHash = XSha1.CalculateHash(data);
            bw.Write(clientToken);
            bw.Write(serverToken);
            bw.Write(firstHash);
            byte[] toCalc = ms.GetBuffer();
            return(XSha1.CalculateHash(toCalc));
        }
Example #2
0
        // removed: unused

        /*
         * private static ushort SWAP2(uint num)
         * {
         *  return (ushort)((((num) >> 8) & 0x00FF) | (((num) << 8) & 0xFF00));
         * }
         */
        #endregion
        #region calculate hash
        private void calculateHash(uint clientToken, uint serverToken)
        {
            if (!valid)
            {
                throw new InvalidOperationException(Resources.invalidCdKeyHashed);
            }

            MemoryStream ms = new MemoryStream(26);
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(clientToken);
            bw.Write(serverToken);

            switch (key.Length)
            {
            case 13:
            case 16:
                bw.Write(product);
                bw.Write(val1);
                bw.Write((int)0);
                bw.Write(val2);
                bw.Write((short)0);

                hash = XSha1.CalculateHash(ms.GetBuffer());
                break;

            case 26:
                bw.Write(product);
                bw.Write(val1);
                bw.Write(val2);
                byte[] buffer = ms.GetBuffer();
                SHA1   sha    = new SHA1Managed();
                hash = sha.ComputeHash(buffer);
                break;

            default:
                break;
            }
            ms.Close();
        }
Example #3
0
 /// <summary>
 /// Calculates the single "broken" SHA-1 hash of the specified
 /// data.
 /// </summary>
 /// <param name="data">The data buffer to hash.</param>
 /// <returns>A 20-byte buffer containing the hash value.</returns>
 public static byte[] HashData(byte[] data)
 {
     return(XSha1.CalculateHash(data));
 }