This class is responsible for calculating the crc32 value of a byte buffer and returning it as a hexadecimal string. : CRC « Security « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Security » CRCScreenshots 
This class is responsible for calculating the crc32 value of a byte buffer and returning it as a hexadecimal string.
 
   
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Crc32.cs" company="kalkie">
//   Patrick Kalkman pkalkie@gmail.com
// </copyright>
// <summary>
//   This class is responsible for calculating the crc32 value of a byte
//   buffer and returning it as a hexadecimal string.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace BinarySeeder.Engine
{
   using System.Globalization;

   /// <summary>
   /// This class is responsible for calculating the crc32 value of a byte
   /// buffer and returning it as a hexadecimal string.
   /// </summary>
   internal class Crc32 
   {
      /// <summary>
      /// Crc32 lookup table generated with polynomial 0xEDB88320.
      /// </summary>
      private readonly uint[] crc32Table = new uint[] 
      {
         0x00000000
         0x770730960xee0e612c0x990951ba0x076dc4190x706af48f0xe963a5350x9e6495a30x0edb88320x79dcb8a40xe0d5e91e
         0x97d2d9880x09b64c2b0x7eb17cbd0xe7b82d070x90bf1d910x1db710640x6ab020f20xf3b971480x84be41de0x1adad47d
         0x6ddde4eb0xf4d4b5510x83d385c70x136c98560x646ba8c00xfd62f97a0x8a65c9ec0x14015c4f0x63066cd90xfa0f3d63
         0x8d080df50x3b6e20c80x4c69105e0xd56041e40xa26771720x3c03e4d10x4b04d4470xd20d85fd0xa50ab56b0x35b5a8fa
         0x42b2986c0xdbbbc9d60xacbcf9400x32d86ce30x45df5c750xdcd60dcf0xabd13d590x26d930ac0x51de003a0xc8d75180
         0xbfd061160x21b4f4b50x56b3c4230xcfba95990xb8bda50f0x2802b89e0x5f0588080xc60cd9b20xb10be9240x2f6f7c87
         0x58684c110xc1611dab0xb6662d3d0x76dc41900x01db71060x98d220bc0xefd5102a0x71b185890x06b6b51f0x9fbfe4a5
         0xe8b8d4330x7807c9a20x0f00f9340x9609a88e0xe10e98180x7f6a0dbb0x086d3d2d0x91646c970xe6635c010x6b6b51f4
         0x1c6c61620x856530d80xf262004e0x6c0695ed0x1b01a57b0x8208f4c10xf50fc4570x65b0d9c60x12b7e9500x8bbeb8ea
         0xfcb9887c0x62dd1ddf0x15da2d490x8cd37cf30xfbd44c650x4db261580x3ab551ce0xa3bc00740xd4bb30e20x4adfa541
         0x3dd895d70xa4d1c46d0xd3d6f4fb0x4369e96a0x346ed9fc0xad6788460xda60b8d00x44042d730x33031de50xaa0a4c5f
         0xdd0d7cc90x5005713c0x270241aa0xbe0b10100xc90c20860x5768b5250x206f85b30xb966d4090xce61e49f0x5edef90e
         0x29d9c9980xb0d098220xc7d7a8b40x59b33d170x2eb40d810xb7bd5c3b0xc0ba6cad0xedb883200x9abfb3b60x03b6e20c
         0x74b1d29a0xead547390x9dd277af0x04db26150x73dc16830xe3630b120x94643b840x0d6d6a3e0x7a6a5aa80xe40ecf0b
         0x9309ff9d0x0a00ae270x7d079eb10xf00f93440x8708a3d20x1e01f2680x6906c2fe0xf762575d0x806567cb0x196c3671
         0x6e6b06e70xfed41b760x89d32be00x10da7a5a0x67dd4acc0xf9b9df6f0x8ebeeff90x17b7be430x60b08ed50xd6d6a3e8
         0xa1d1937e0x38d8c2c40x4fdff2520xd1bb67f10xa6bc57670x3fb506dd0x48b2364b0xd80d2bda0xaf0a1b4c0x36034af6
         0x41047a600xdf60efc30xa867df550x316e8eef0x4669be790xcb61b38c0xbc66831a0x256fd2a00x5268e2360xcc0c7795
         0xbb0b47030x220216b90x5505262f0xc5ba3bbe0xb2bd0b280x2bb45a920x5cb36a040xc2d7ffa70xb5d0cf310x2cd99e8b
         0x5bdeae1d0x9b64c2b00xec63f2260x756aa39c0x026d930a0x9c0906a90xeb0e363f0x720767850x050057130x95bf4a82
         0xe2b87a140x7bb12bae0x0cb61b380x92d28e9b0xe5d5be0d0x7cdcefb70x0bdbdf210x86d3d2d40xf1d4e2420x68ddb3f8
         0x1fda836e0x81be16cd0xf6b9265b0x6fb077e10x18b747770x88085ae60xff0f6a700x66063bca0x11010b5c0x8f659eff
         0xf862ae690x616bffd30x166ccf450xa00ae2780xd70dd2ee0x4e0483540x3903b3c20xa76726610xd06016f70x4969474d
         0x3e6e77db0xaed16a4a0xd9d65adc0x40df0b660x37d83bf00xa9bcae530xdebb9ec50x47b2cf7f0x30b5ffe90xbdbdf21c
         0xcabac28a0x53b393300x24b4a3a60xbad036050xcdd706930x54de57290x23d967bf0xb3667a2e0xc4614ab80x5d681b02
         0x2a6f2b940xb40bbe370xc30c8ea10x5a05df1b0x2d02ef8d
      };

      /// <summary>
      /// Calculates the CRC32 value of the given buffer.
      /// </summary>
      /// <param name="buffer">The buffer of which the crc32 must be calculated.</param>
      /// <returns>The calculated crc32 value as a hex string.</returns>
      internal virtual string CalculateCrc32(byte[] buffer)
      {
         uint calculatedCrc = 0xFFFFFFFF;

         foreach (byte byteToCalculate in buffer)
         {
            calculatedCrc = (calculatedCrc >> 8^ crc32Table[byteToCalculate ^ (calculatedCrc & 0x000000FF)];
         }

         return (~calculatedCrc).ToString("X8", CultureInfo.InvariantCulture);
      }
   }
}

   
  
Related examples in the same category
1.A utility class to compute CRC32
2.Generate a table for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
3.Calculates a 32 bit Cyclic Redundancy Checksum (CRC) using the same polynomial used by Zip.
4.Do CRC32 hashing.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.