Esempio n. 1
0
        static public int Compute(byte[] data, int offset, int count)
        {
            var crc = new OptimizedCRC();

            crc.Update(data, offset, count);
            return(crc.Value);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the CRC32 hash for a file, if possible
        /// </summary>
        /// <param name="file">Path to the file</param>
        /// <returns>String representation of the CRC32 hash of the file</returns>
        private string GetCRCFromFile(string file)
        {
            using (OptimizedCRC crc = new OptimizedCRC())
                using (BinaryReader reader = new BinaryReader(File.OpenRead(file)))
                {
                    byte[] buffer = new byte[8 * 1024];
                    int    read   = Int32.MaxValue;
                    while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        crc.Update(buffer, 0, read);
                    }

                    crc.Update(buffer, 0, 0);
                    byte[] crcHash = BitConverter.GetBytes(crc.Value).Reverse().ToArray();

                    return(ByteArrayToString(crcHash));
                }
        }