/// <summary> /// 计算字节数据的crc32值 /// </summary> /// <param name="data">二进制数据</param> /// <returns>crc32值</returns> public static uint CheckSumBytes(byte[] data) { CRC32 crc = new CRC32(); crc.Write(data, 0, data.Length); return(crc.Sum()); }
/// <summary> /// 检验 /// </summary> /// <param name="data">字节数据</param> /// <param name="offset">偏移位置</param> /// <param name="count">字节数</param> /// <returns></returns> public static uint CheckSumSlice(byte[] data, int offset, int count) { CRC32 crc = new CRC32(); crc.Write(data, offset, count); return(crc.Sum()); }
/// <summary> /// 计算沙盒文件的crc32值 /// </summary> /// <param name="filePath">沙盒文件全路径</param> /// <returns>crc32值</returns> public static uint checkSumFile(string filePath) { CRC32 crc = new CRC32(); int bufferLen = 32 * 1024; using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { byte[] buffer = new byte[bufferLen]; while (true) { int n = fs.Read(buffer, 0, bufferLen); if (n == 0) { break; } crc.Write(buffer, 0, n); } } return(crc.Sum()); }