示例#1
0
        /// <summary>
        /// 计算字节数据的crc32值
        /// </summary>
        /// <param name="data">二进制数据</param>
        /// <returns>crc32值</returns>
        public static uint CheckSumBytes(byte[] data)
        {
            CRC32Util crc = new CRC32Util();

            crc.Write(data, 0, data.Length);
            return(crc.Sum());
        }
示例#2
0
        /// <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)
        {
            CRC32Util crc = new CRC32Util();

            crc.Write(data, offset, count);
            return(crc.Sum());
        }
示例#3
0
        /// <summary>
        /// 计算沙盒文件的crc32值
        /// </summary>
        /// <param name="filePath">沙盒文件全路径</param>
        /// <returns>crc32值</returns>
        public static uint checkSumFile(string filePath)
        {
            CRC32Util crc       = new CRC32Util();
            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());
        }