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


C# Crc32.TransformBlock方法代码示例

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


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

示例1: CalculateHashes_here

        protected static Hashes CalculateHashes_here(string strPath, OnHashProgress onHashProgress)
        {
            FileStream fs;
            Hashes rhash=new Hashes();
            FileInfo fi = new FileInfo(strPath);
            fs = fi.OpenRead();
            int lChunkSize = 9728000;

            //string sHash = "";
            long nBytes = (long)fs.Length;

            long nBytesRemaining = (long)fs.Length;
            int nBytesToRead = 0;

            long nBlocks = nBytes / lChunkSize;
            long nRemainder = nBytes % lChunkSize; //mod
            if (nRemainder > 0)
                nBlocks++;

            byte[] baED2KHash = new byte[16 * nBlocks];

            if (nBytes > lChunkSize)
                nBytesToRead = lChunkSize;
            else
                nBytesToRead = (int)nBytesRemaining;

            if (onHashProgress != null)
                onHashProgress(strPath, 0);

            MD4 md4 = MD4.Create();
            MD5 md5 = MD5.Create();
            SHA1 sha1 = SHA1.Create();
            Crc32 crc32=new Crc32();

            byte[] ByteArray = new byte[nBytesToRead];

            long iOffSet = 0;
            long iChunkCount = 0;
            while (nBytesRemaining > 0)
            {
                iChunkCount++;

                Console.WriteLine("Hashing Chunk: " + iChunkCount.ToString());

                int nBytesRead = fs.Read(ByteArray, 0, nBytesToRead);
                byte[] baHash = md4.ComputeHash(ByteArray, 0, nBytesRead);
                md5.TransformBlock(ByteArray, 0, nBytesRead, ByteArray, 0);
                sha1.TransformBlock(ByteArray, 0, nBytesRead, ByteArray, 0);
                crc32.TransformBlock(ByteArray, 0, nBytesRead, ByteArray, 0);
                int percentComplete = (int)((float)iChunkCount / (float)nBlocks * 100);
                if (onHashProgress != null)
                    onHashProgress(strPath, percentComplete);

                int j = (int)((iChunkCount - 1) * 16);
                for (int i = 0; i < 16; i++)
                    baED2KHash[j + i] = baHash[i];

                iOffSet += lChunkSize;
                nBytesRemaining = nBytes - iOffSet;
                if (nBytesRemaining < lChunkSize)
                    nBytesToRead = (int)nBytesRemaining;

            }
            md5.TransformFinalBlock(ByteArray, 0, 0);
            sha1.TransformFinalBlock(ByteArray, 0, 0);
            crc32.TransformFinalBlock(ByteArray, 0, 0);


            fs.Close();

            if (onHashProgress != null)
                onHashProgress(strPath, 100);

            byte[] baHashFinal = md4.ComputeHash(baED2KHash);
            rhash.ed2k = BitConverter.ToString(baHashFinal).Replace("-", "").ToUpper();
            rhash.crc32 = BitConverter.ToString(crc32.Hash).Replace("-", "").ToUpper();
            rhash.md5 = BitConverter.ToString(md5.Hash).Replace("-", "").ToUpper(); 
            rhash.sha1 = BitConverter.ToString(sha1.Hash).Replace("-", "").ToUpper(); 
            return rhash;
        }
开发者ID:ministerkrister,项目名称:Emulators,代码行数:80,代码来源:Hasher.cs


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