/// <summary> /// Calculates the double-pass "broken" SHA-1 hash of the /// specified data. This method is not CLS-compliant. /// </summary> /// <param name="data">The data buffer to hash.</param> /// <param name="clientToken">The client token, /// a randomly-generated value specified by the client.</param> /// <param name="serverToken">The server token, a /// randomly-generated value specified by the server.</param> /// <returns>A 20-byte buffer containing the hash value.</returns> //[CLSCompliant(false)] 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)); }
// 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("The CD key was invalid and the hash could not be calculated."); } 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(); }
/// <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)); }