Class Crc32Hash
Implements a 32-bit CRC hash algorithm compatible with Zip etc.
Inherited Members
Namespace: mk.helpers
Assembly: mk.helpers.dll
Syntax
public sealed class Crc32Hash : HashAlgorithm, ICryptoTransform, IDisposable
Remarks
Crc32 should only be used for backward compatibility with older file formats and algorithms. It is not secure enough for new applications. If you need to call multiple times for the same data either use the HashAlgorithm interface or remember that the result of one Compute call needs to be ~ (XOR) before being passed in as the seed for the next Compute call.
Constructors
Crc32Hash()
Initializes a new instance of the Crc32Hash class using the default polynomial and seed values.
Declaration
public Crc32Hash()
Crc32Hash(uint, uint)
Initializes a new instance of the Crc32Hash class using the specified polynomial and seed values.
Declaration
public Crc32Hash(uint polynomial, uint seed)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | polynomial | The polynomial value to use for CRC32 calculation. |
| uint | seed | The seed value to use for CRC32 calculation. |
Fields
DefaultPolynomial
Default polynomial value for CRC32 calculation.
Declaration
public const uint DefaultPolynomial = 3988292384
Field Value
| Type | Description |
|---|---|
| uint |
DefaultSeed
Default seed value for CRC32 calculation.
Declaration
public const uint DefaultSeed = 4294967295
Field Value
| Type | Description |
|---|---|
| uint |
Properties
HashSize
Gets the size, in bits, of the computed hash code.
Declaration
public override int HashSize { get; }
Property Value
| Type | Description |
|---|---|
| int | The size, in bits, of the computed hash code. |
Overrides
Methods
Compute(byte[])
Computes the CRC32 hash value for the specified buffer using the default seed value.
Declaration
public static uint Compute(byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The input buffer for which to compute the hash value. |
Returns
| Type | Description |
|---|---|
| uint | The computed CRC32 hash value. |
Compute(uint, byte[])
Computes the CRC32 hash value for the specified buffer using the specified seed value.
Declaration
public static uint Compute(uint seed, byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | seed | The seed value to use for CRC32 calculation. |
| byte[] | buffer | The input buffer for which to compute the hash value. |
Returns
| Type | Description |
|---|---|
| uint | The computed CRC32 hash value. |
Compute(uint, uint, byte[])
Computes the CRC32 hash value for the specified buffer using the specified polynomial and seed values.
Declaration
public static uint Compute(uint polynomial, uint seed, byte[] buffer)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | polynomial | The polynomial value to use for CRC32 calculation. |
| uint | seed | The seed value to use for CRC32 calculation. |
| byte[] | buffer | The input buffer for which to compute the hash value. |
Returns
| Type | Description |
|---|---|
| uint | The computed CRC32 hash value. |
HashCore(byte[], int, int)
When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.
Declaration
protected override void HashCore(byte[] array, int ibStart, int cbSize)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | array | The input to compute the hash code for. |
| int | ibStart | The offset into the byte array from which to begin using data. |
| int | cbSize | The number of bytes in the byte array to use as data. |
Overrides
HashFinal()
When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic stream object.
Declaration
protected override byte[] HashFinal()
Returns
| Type | Description |
|---|---|
| byte[] | The computed hash code. |
Overrides
Initialize()
Initializes an implementation of the HashAlgorithm class.
Declaration
public override void Initialize()