当前位置: 首页>>代码示例>>C#>>正文


C# Crc32类代码示例

本文整理汇总了C#中Crc32的典型用法代码示例。如果您正苦于以下问题:C# Crc32类的具体用法?C# Crc32怎么用?C# Crc32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Crc32类属于命名空间,在下文中一共展示了Crc32类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckSum

        public static uint CheckSum(Stream s)
        {
            var crc32 = new Crc32();
            crc32.ComputeHash(s);

            return crc32.CrcValue;
        }
开发者ID:kirkpabk,项目名称:higgs,代码行数:7,代码来源:HashFunction.cs

示例2: CreateData

        public static byte[] CreateData(IPacket packet)
        {
            if (packet == null)
                throw new ArgumentNullException("packet");

            var content = packet.GetContent();
            var idLengthContent = new byte[content.Length + PacketIdFieldWidth + ContentLengthFieldWidth];

            idLengthContent[0] = (byte)packet.Id;

            var contentLength = BitConverter.GetBytes(content.Length);
            idLengthContent[1] = contentLength[0]; // Not in the mood for a for loop
            idLengthContent[2] = contentLength[1];
            idLengthContent[3] = contentLength[2];
            idLengthContent[4] = contentLength[3];

            for (int i = (PacketIdFieldWidth + ContentLengthFieldWidth); i < idLengthContent.Length; ++i)
                idLengthContent[i] = content[i - (PacketIdFieldWidth + ContentLengthFieldWidth)];

            byte[] checksum;
            using (var provider = new Crc32())
                checksum = provider.ComputeHash(idLengthContent, 0, idLengthContent.Length);

            using (var ms = new MemoryStream())
            {
                ms.Write(checksum, 0, ChecksumWidth);
                ms.Write(idLengthContent, 0, idLengthContent.Length);
                return ms.ToArray();
            }
        }
开发者ID:nikeee,项目名称:NetDiscovery,代码行数:30,代码来源:PacketHandler.cs

示例3: Compress

        public static byte[] Compress( byte[] buffer )
        {
            using ( MemoryStream ms = new MemoryStream() )
            using ( BinaryWriter writer = new BinaryWriter( ms ) )
            {
                uint checkSum = 0;

                using ( var crc = new Crc32() )
                {
                    checkSum = BitConverter.ToUInt32( crc.ComputeHash( buffer ), 0 );
                }

                byte[] compressed = DeflateBuffer( buffer );

                Int32 poslocal = WriteHeader( writer, LocalFileHeader );
                WriteLocalFile( writer, "z", checkSum, ( UInt32 )buffer.Length, compressed );

                Int32 posCDR = WriteHeader( writer, CentralDirectoryHeader );
                UInt32 CDRSize = WriteCentralDirectory( writer, "z", checkSum, ( UInt32 )compressed.Length, ( UInt32 )buffer.Length, poslocal );

                Int32 posEOD = WriteHeader( writer, EndOfDirectoryHeader );
                WriteEndOfDirectory( writer, 1, CDRSize, posCDR );

                return ms.ToArray();
            }
        }
开发者ID:wheybags,项目名称:steamirc,代码行数:26,代码来源:ZipUtil.cs

示例4: checksum_file

        static int checksum_file(string file, ref byte[] p, ref uint size, ref uint crc)
        {
            int length;
            byte[] data;
            Stream f;

            f = fopen(file, "rb");
            if (f == null)
                return -1;

            length = (int)f.Length;

            /* allocate space for entire file */
            data = new byte[length];

            /* read entire file into memory */
            f.Read(data, 0, length);

            size = (uint)length;
            //crc = crc32(0L, data, length);
            Crc32 crc32 = new Crc32();
            string hash = "";
            foreach (byte b in crc32.ComputeHash(data)) hash += b.ToString("x2").ToLower();
            crc = Convert.ToUInt32(hash,16);
            if (p != null)
                p = data;
            else
                data = null;

            fclose(f);

            return 0;
        }
开发者ID:DarrenRainey,项目名称:xnamame036,代码行数:33,代码来源:fileio.cs

示例5: zip

    private void zip(string strFile, ZipOutputStream s, string staticFile)
    {
        if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar) strFile += Path.DirectorySeparatorChar;
        Crc32 crc = new Crc32();
        string[] filenames = Directory.GetFileSystemEntries(strFile);
        foreach (string file in filenames)
        {

            if (Directory.Exists(file))
            {
                zip(file, s, staticFile);
            }

            else // 否则直接压缩文件
            {
                //打开压缩文件
                FileStream fs = File.OpenRead(file);

                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);
                string tempfile = file.Substring(staticFile.LastIndexOf("\\") + 1);
                ZipEntry entry = new ZipEntry(tempfile);

                entry.DateTime = DateTime.Now;
                entry.Size = fs.Length;
                fs.Close();
                crc.Reset();
                crc.Update(buffer);
                entry.Crc = crc.Value;
                s.PutNextEntry(entry);

                s.Write(buffer, 0, buffer.Length);
            }
        }
    }
开发者ID:QingWei-Li,项目名称:AutoBackupFolder,代码行数:35,代码来源:ZipFloClass.cs

示例6: Hash

 public string Hash(string input)
 {
     using (var crc = new Crc32())
     {
         var byteArray = crc.ComputeHash(Encoding.Unicode.GetBytes(input));
         return byteArray.Aggregate("", (current, b) => current + b.ToString("x2"));
     }
 }
开发者ID:eByte23,项目名称:Smidge,代码行数:8,代码来源:Crc.cs

示例7: CalcSecureHash

 public static int CalcSecureHash(string text)
 {
     Crc32 crc32 = new Crc32();
     String hash = String.Empty;
     byte[] bytes = System.Text.ASCIIEncoding.ASCII.GetBytes(text);
     byte[] data = crc32.ComputeHash(bytes);
     int res = data[0] + (data[1] * 256) + (data[2] * 65536) + ( data[3] * 16777216);
     return res;
 }
开发者ID:ThomasBoeriis,项目名称:VidStockDatabse,代码行数:9,代码来源:CRC32.cs

示例8: GetIndex

 public int GetIndex(string key)
 {
     using (var crc32 = new Crc32())
     {
         var keyBytes = Encoding.UTF8.GetBytes(key);
         var hashedKeyBytes = crc32.ComputeHash(keyBytes);
         var hash = BitConverter.ToUInt32(hashedKeyBytes, 0);
         return (int)hash & _mask;
     }
 }
开发者ID:orangeloop,项目名称:couchbase-net-client,代码行数:10,代码来源:VBucketKeyMapper.cs

示例9: Main

        static void Main(string[] args)
        {
            Crc32 crc32 = new Crc32();
            String hash = String.Empty;

            Console.Write("Enter Path: ");
            string path = Console.ReadLine();

            var dir = new DirectoryInfo(path);
            var files = new List<string>();
            var CRC = new List<string>();
            foreach (FileInfo file in dir.GetFiles())
            {
                using (FileStream fs = File.Open(file.FullName, FileMode.Open))
                foreach (byte b in crc32.ComputeHash(fs)) hash += b.ToString("x2").ToLower();

                files.Add(file.FullName);
                CRC.Add(file.FullName + " - " + hash);
            }

            foreach (var element in CRC)
            {
                Console.WriteLine(element);
            }

            path = path + "/CRC.txt";

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (FileStream file = File.Create(path))
            {
                Byte[] info = new UTF8Encoding(true).GetBytes("");
                file.Write(info, 0, info.Length);
            }

            using (System.IO.StreamWriter file_dump =
            new System.IO.StreamWriter(@path, true))
            {
                foreach (var element in CRC)
                {
                    file_dump.WriteLine(element);
                }

                file_dump.WriteLine();
            }

            Console.WriteLine(" \t \t  Dump Done");

            //Комменты у меня (с) Константин Лебейко

            Console.ReadKey();
        }
开发者ID:maroder-king,项目名称:CRC,代码行数:55,代码来源:Program.cs

示例10: AddStreamAsync

        public async Task AddStreamAsync(string key, Stream stream)
        {
            var crc = new Crc32();
            var useStream = stream as BufferedStream ?? new BufferedStream(stream);

            byte[] buffer = new byte[0x1000];
            int bytesRead;
            while ((bytesRead = await useStream.ReadAsync(buffer, 0, 0x1000)) > 0)
                crc.Update(buffer, 0, bytesRead);

            _entries.Add(key, crc.Value);
        }
开发者ID:jzebedee,项目名称:sharpsfv,代码行数:12,代码来源:SfvBuilder.cs

示例11: Tests

 public void Tests()
 {
     var crc = new Crc32();
     Assert.AreEqual(0, crc.Value);
     crc.Update(145);
     Assert.AreEqual(1426738271, crc.Value);
     crc.Update(123456789);
     Assert.AreEqual(1147030863, crc.Value);
     byte[] data = new byte[] { 145, 234, 156 };
     crc.Update(data);
     Assert.AreEqual(3967437022, crc.Value);
 }
开发者ID:ArildF,项目名称:GitSharp,代码行数:12,代码来源:Crc32Tests.cs

示例12: Main

    public static int Main(string[] args)
    {
        if (args.Length == 0) {
            ShowHelp();
            return 1;
        }

        var parser = new ArgumentParser(args);

        if (!File.Exists(file_)) {
            Console.Error.WriteLine("Cannot find file {0}", file_);
            ShowHelp();
            return 1;
        }

        using (FileStream checksumStream = File.OpenRead(file_)) {

            byte[] buffer = new byte[4096];
            int bytesRead;

            switch (parser.Command) {
                case Command.Help:
                    ShowHelp();
                    break;

                case Command.Crc32:
                    var currentCrc = new Crc32();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentCrc.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("CRC32 for {0} is 0x{1:X8}", args[0], currentCrc.Value);
                    break;

                case Command.BZip2:
                    var currentBZip2Crc = new BZip2Crc();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentBZip2Crc.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("BZip2CRC32 for {0} is 0x{1:X8}", args[0], currentBZip2Crc.Value);
                    break;

                case Command.Adler:
                    var currentAdler = new Adler32();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentAdler.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("Adler32 for {0} is 0x{1:X8}", args[0], currentAdler.Value);
                    break;
            }
        }
        return 0;
    }
开发者ID:icsharpcode,项目名称:SharpZipLib,代码行数:52,代码来源:Cmd_Checksum.cs

示例13: getChecksum

		public long getChecksum() {
			byte[] bytes = new byte[32];
			Crc32 checksum=new Crc32();
			System.IO.MemoryStream ms = new System.IO.MemoryStream();
			System.IO.BinaryWriter bytebuffer = new System.IO.BinaryWriter(ms);
			
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					bytebuffer.Write(getPixel(x, y));
					bytes=checksum.ComputeHash(ms);
				}
			}
			return BitConverter.ToInt64(bytes,0);
		}
开发者ID:N3X15,项目名称:VoxelSim,代码行数:14,代码来源:Channel.cs

示例14: WriteZipFile

        public static void WriteZipFile(List<FileDetails> filesToZip, string path,string manifestPath,string manifest )
        {
            int compression = 9;
          
            FileDetails fd = new FileDetails(manifest, manifestPath,manifestPath);
            filesToZip.Insert(0,fd);

            foreach (FileDetails obj in filesToZip)
                if (!File.Exists(obj.FilePath))
                    throw new ArgumentException(string.Format("The File {0} does not exist!", obj.FileName));

            Object _locker=new Object();
            lock(_locker)
            {
                Crc32 crc32 = new Crc32();
                ZipOutputStream stream = new ZipOutputStream(File.Create(path));
                stream.SetLevel(compression);
                for (int i = 0; i < filesToZip.Count; i++)
                {
                    ZipEntry entry = new ZipEntry(filesToZip[i].FolderInfo + "/" + filesToZip[i].FileName);
                    entry.DateTime = DateTime.Now;
                    if (i == 0)
                    {
                        entry = new ZipEntry(manifest);
                    }

                    using (FileStream fs = File.OpenRead(filesToZip[i].FilePath))
                    {
                        byte[] buffer = new byte[fs.Length];
                        fs.Read(buffer, 0, buffer.Length);
                        entry.Size = fs.Length;
                        fs.Close();
                        crc32.Reset();
                        crc32.Update(buffer);
                        entry.Crc = crc32.Value;
                        stream.PutNextEntry(entry);
                        stream.Write(buffer, 0, buffer.Length);
                    }
                }
                stream.Finish();
                stream.Close();
                DeleteManifest(manifestPath);
            }
            

          

           
        }
开发者ID:electrono,项目名称:veg-web,代码行数:49,代码来源:PackageWriterBase.cs

示例15: TestOperatorEquality

        public void TestOperatorEquality()
        {
            Crc32 empty = new Crc32();
            Crc32 value = new Crc32("Hello");
            Crc32 copy = new Crc32(value.Value);

            Assert.IsTrue(value == copy);
            Assert.IsFalse(value == empty);
            Assert.IsTrue(value == copy.Value);
            Assert.IsFalse(value == empty.Value);

            Assert.IsFalse(value != copy);
            Assert.IsTrue(value != empty);
            Assert.IsFalse(value != copy.Value);
            Assert.IsTrue(value != empty.Value);
        }
开发者ID:langimike,项目名称:CSharpTest.Net.Collections,代码行数:16,代码来源:TestCrc32.cs


注:本文中的Crc32类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。