/// <summary> /// Returns the CRC for the given array of bytes. /// </summary> /// <param name="array">The byte array.</param> /// <returns>The CRC for the given byte array.</returns> private long CalculateCrc(byte[] array) { string srchash = string.Empty; using (Crc32 crcCalc = new Crc32()) { foreach (byte b in crcCalc.ComputeHash(array)) { srchash += b.ToString("x2", CultureInfo.InvariantCulture).ToLower(CultureInfo.InvariantCulture); } } return(long.Parse(srchash, NumberStyles.HexNumber, CultureInfo.InvariantCulture)); }
/// <summary> /// Gets the CRC. /// </summary> /// <param name="data">The data.</param> /// <returns>The CRC value for the supplied data.</returns> public static int GetCrc(byte[] data) { if (data == null) { return(0); } string srchash = string.Empty; using (Crc32 crc = new Crc32()) { srchash = crc.ComputeHash(data).Aggregate(srchash, (current, b) => current + b.ToString("x2").ToLower(CultureInfo.InvariantCulture)); } return(int.Parse(srchash, NumberStyles.HexNumber)); }