示例#1
0
 /// <summary>
 /// Test data
 /// </summary>
 /// <param name="args"></param>
 static void Main(string[] args)
 {
     Crc32 crc32 = new Crc32();
     string hash = string.Empty;
     using (FileStream fs = File.Open("loremipsum.txt", FileMode.Open))
         foreach (byte b in crc32.ComputeHash(fs)) hash += b.ToString("x2").ToLower();
     Console.WriteLine("CRC-32 is {0}", hash);
 }
示例#2
0
 public static uint GetStreamCRC32(Stream stream)
 {
     if (stream == null)
         throw new ArgumentNullException("stream");
     if (!stream.CanRead)
         throw new ArgumentException("stream is not readable.");
     stream.Position = 0;
     Crc32 crc32 = new Crc32();
     byte[] buf = new byte[4096];
     int len = 0;
     while ((len = stream.Read(buf, 0, buf.Length)) != 0)
     {
         crc32.Update(buf, 0, len);
     }
     stream.Position = 0;
     return crc32.Value;
 }
示例#3
0
        public static uint GetFileCRC32(string path)
        {
            if (path == null)
                throw new ArgumentNullException("path");

            Crc32 crc32 = new Crc32();
            byte[] buf = new byte[4096];
            int len = 0;
            using (FileStream fs = new FileStream(path, FileMode.Open))
            {
                while ((len = fs.Read(buf, 0, buf.Length)) != 0)
                {
                    crc32.Update(buf, 0, len);
                }
            }
            return crc32.Value;
        }