• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Crc32类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Inject

 public static byte[] Inject(byte[] png, byte[] data)
 {
     VerifyPng(png);
     var size = new byte[] { (byte)((data.Length >> 24) & 0xff), (byte)((data.Length >> 16) & 0xff),
                             (byte)((data.Length >> 8) & 0xff),  (byte)(data.Length & 0xff) };
     var crc = new Crc32().ComputeHash(data);
     var result = new byte[png.Length + size.Length + tag.Length + data.Length + crc.Length];
     var index = 0;
     png.CopyTo(result, index); index += png.Length - iend.Length;
     size.CopyTo(result, index); index += size.Length;
     tag.CopyTo(result, index); index += tag.Length;
     data.CopyTo(result, index); index += data.Length;
     crc.CopyTo(result, index); index += crc.Length;
     iend.CopyTo(result, index);
     return result;
 }
开发者ID:bcdev-com,项目名称:liveconnect,代码行数:16,代码来源:PngCloak.cs


示例17: Crc32

        /// <summary>
        /// 压缩多个文件或目录
        /// </summary>
        /// <param name="输出压缩文件路径">压缩包文件路径</param>
        /// <param name="压缩级别">压缩程度,范围0-9,数值越大,压缩程序越高</param>
        ///// <param name="密码">密码,如不需要设密码只需传入null或空字符串</param>
        /// <param name="目录或文件">多个文件或目录</param>
        public static void 压缩(string 输出压缩文件路径, int 压缩级别, params string[] 目录或文件)
        {
            Crc32 crc = new Crc32();
            ZipOutputStream outPutStream = new ZipOutputStream(File.Create(输出压缩文件路径));
            outPutStream.SetLevel(压缩级别); // 0 - store only to 9 - means best compression
            //if (!密码.IsNullOrEmpty()) outPutStream.Password = 密码;  //密码部分有问题,设了之后输入对密码也没法解压
            outPutStream.UseZip64 = UseZip64.Off;   //执行此命令可修正Android上解压缩出现的这个错误:08-14 09:08:38.111: D/outpath(17145): Cannot read local header version 45
            递归处理("", 目录或文件, crc, outPutStream);

            //GetAllDirectories(rootPath);
            //while (rootPath.LastIndexOf("\\") + 1 == rootPath.Length)//检查路径是否以"\"结尾
            //{
            //    rootPath = rootPath.Substring(0, rootPath.Length - 1);//如果是则去掉末尾的"\"
            //}
            //string rootMark = rootPath.Substring(0, rootPath.LastIndexOf("\\") + 1);//得到当前路径的位置,以备压缩时将所压缩内容转变成相对路径
            //foreach (string file in files)
            //{
            //    FileStream fileStream = File.OpenRead(file);//打开压缩文件
            //    byte[] buffer = new byte[fileStream.Length];
            //    fileStream.Read(buffer, 0, buffer.Length);
            //    ZipEntry entry = new ZipEntry(file.Replace(rootMark, string.Empty));
            //    entry.DateTime = DateTime.Now;
            //    // set Size and the crc, because the information
            //    // about the size and crc should be stored in the header
            //    // if it is not set it is automatically written in the footer.
            //    // (in this case size == crc == -1 in the header)
            //    // Some ZIP programs have problems with zip files that don't store
            //    // the size and crc in the header.
            //    entry.Size = fileStream.Length;
            //    fileStream.Close();
            //    crc.Reset();
            //    crc.Update(buffer);
            //    entry.Crc = crc.Value;
            //    outPutStream.PutNextEntry(entry);
            //    outPutStream.Write(buffer, 0, buffer.Length);
            //}
            //this.files.Clear();
            //foreach (string emptyPath in paths)
            //{
            //    ZipEntry entry = new ZipEntry(emptyPath.Replace(rootMark, string.Empty) + "/");
            //    outPutStream.PutNextEntry(entry);
            //}
            //this.paths.Clear();
            outPutStream.Finish();
            outPutStream.Close();
        }
开发者ID:manasheep,项目名称:Core3,代码行数:53,代码来源:SharpZip.cs


示例18: AssertCrc32

        private static void AssertCrc32(byte[] input, int expected)
        {
            Crc32 crc = new Crc32(input);
            Assert.AreEqual(expected, crc.Value);

            crc = new Crc32(0);
            crc.Add(input);
            Assert.AreEqual(expected, crc.Value);

            crc = new Crc32();
            crc.Add(input, 0, input.Length);
            Assert.AreEqual(expected, crc.Value);

            crc = new Crc32();
            foreach (byte b in input)
                crc.Add(b);
            Assert.AreEqual(expected, crc.Value);
        }
开发者ID:langimike,项目名称:CSharpTest.Net.Collections,代码行数:18,代码来源:TestCrc32.cs


示例19: CalculateCRC32

        public static long CalculateCRC32(
            string theFileName)
        {
            using (FileStream theFileStream = File.OpenRead(theFileName))
            {
                Crc32 theCRC32Provider = new Crc32();

                byte[] theBuffer = new byte[theFileStream.Length];

                theFileStream.Read(theBuffer, 0, theBuffer.Length);

                theCRC32Provider.Reset();

                theCRC32Provider.Update(theBuffer);

                return theCRC32Provider.Value;
            }
        }
开发者ID:jzengerling,项目名称:karaokidex,代码行数:18,代码来源:IOOperations.cs


示例20: GetHash

        public static string GetHash(string filename)
        {
            Crc32 crc32 = new Crc32();
            String hash = String.Empty;

            try
            {
                if (!File.Exists(filename))
                    throw new IOException("Unknown File");

                using (FileStream fs = File.Open(filename, FileMode.Open))
                    foreach (byte b in crc32.ComputeHash(fs)) hash += b.ToString("x2").ToLower();
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            return hash;
        }
开发者ID:ksmaze,项目名称:YetAnotherRelogger,代码行数:19,代码来源:CRC.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CreateCollectionOperation类代码示例发布时间:2022-05-24
下一篇:
C# CraftResource类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap