Exemplo n.º 1
0
        /// <summary>
        /// Verify given stream data against given checksum.
        /// </summary>
        /// <param name="stream">Stream data to check.</param>
        /// <param name="sum">Checksum.</param>
        /// <returns>true if data matches checksum, false otherwise.</returns>
        public bool Verify(Stream stream, byte[] sum)
        {
            if (sum == null)
            {
                throw new ArgumentNullException("sum");
            }

            // Crc64 sum is 8 bytes
            if (sum.Length != 8)
            {
                return(false);
            }

            byte[] hexSum = Crc64ISO.GetStreamCRC64(stream);

            for (int i = 0; i < hexSum.Length; i++)
            {
                if (hexSum[i] != sum[i])
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculate checksum from byte table data.
        /// </summary>
        /// <param name="data">Data as byte table.</param>
        /// <returns>Checksum.</returns>
        public byte[] Calculate(byte[] data)
        {
            MemoryStream ms = new MemoryStream(data);

            byte[] hexSum = Crc64ISO.GetStreamCRC64(ms);
            ms.Close();
            return(hexSum);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Verify given byte data against given checksum.
        /// </summary>
        /// <param name="data">Data to check as byte table.</param>
        /// <param name="sum">Checksum.</param>
        /// <returns>true if data matches checksum, false otherwise.</returns>
        public bool Verify(byte[] data, byte[] sum)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (sum == null)
            {
                throw new ArgumentNullException("sum");
            }

            // Crc64 sum is 4 bytes
            if (sum.Length != 4)
            {
                return(false);
            }

            MemoryStream msData = new MemoryStream(data);
            MemoryStream msSum  = new MemoryStream(sum);

            byte[] hexSum = Crc64ISO.GetStreamCRC64(msData);
            int    ind    = 0;
            bool   valid  = true;

            while (ind < hexSum.Length && valid)
            {
                if (hexSum[ind] != sum[ind])
                {
                    valid = false;
                }
                else
                {
                    ++ind;
                }
            }

            msData.Close();
            msSum.Close();
            return(valid);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Calculate checksum from stream data.
 /// </summary>
 /// <param name="stream">Data as stream.</param>
 /// <returns>Checksum.</returns>
 public byte[] Calculate(Stream stream)
 {
     byte[] hexSum = Crc64ISO.GetStreamCRC64(stream);
     return(hexSum);
 }