Table of Contents

CyclicRedundancyCheck32 Class

Definition

Namespace
Cuemon.Security
Assemblies
Cuemon.Core.dll
Source
src/Cuemon.Core/Security/CyclicRedundancyCheck32.cs

Provides a CRC-32 implementation of the CRC (Cyclic Redundancy Check) checksum algorithm for 32-bit hash values. This class cannot be inherited.

public sealed class CyclicRedundancyCheck32 : CyclicRedundancyCheck, IHash, IConfigurable<CyclicRedundancyCheckOptions>
Inheritance
object
CyclicRedundancyCheck32
Implements
Inherited Members

Examples

The following example shows how to compute a CRC-32 checksum with the common reflected configuration.

using System;
using System.Text;
using Cuemon;
using Cuemon.Security;

namespace MyApp.Examples;

public static class CyclicRedundancyCheck32Example
{
    public static void Demonstrate()
    {
        var checksum = new CyclicRedundancyCheck32(setup: options =>
        {
            options.ByteOrder = Endianness.BigEndian;
            options.ReflectInput = true;
            options.ReflectOutput = true;
        });

        HashResult result = checksum.ComputeHash(Encoding.ASCII.GetBytes("123456789"));

        Console.WriteLine(result.ToHexadecimalString().ToLowerInvariant());
        Console.WriteLine(checksum.InitialValue);
        Console.WriteLine(checksum.FinalXor);

        var alternate = new CyclicRedundancyCheck32(polynomial: 0xEDB88320, initialValue: 0xFFFFFFFF, finalXor: 0xFFFFFFFF);
        Console.WriteLine(alternate.ComputeHash("Cuemon").ToBase64String());
    }
}

Constructors

Name Description
CyclicRedundancyCheck32(uint, uint, uint, Action<CyclicRedundancyCheckOptions>)

Initializes a new instance of the CyclicRedundancyCheck32 class.

Methods

Name Description
ComputeHash(byte[])

Computes the hash value for the specified byte array.

PolynomialIndexInitializer(byte)

Returns the initial value for the specified index of the polynomial LookupTable.

PolynomialSlotCalculator(ref ulong, ulong)

Computes the polynomial checksum value in steps of 8 (0-7) x 256 (0-255) giving a total of 2048 times.

See Also