Table of Contents

HashFactory Class

Definition

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

Provides access to factory methods for creating and configuring Hash instances.

public static class HashFactory
Inheritance
HashFactory

Examples

The following example shows how to compute non-cryptographic hashes using HashFactory. It demonstrates FNV-1a 32-bit, CRC-32, and FNV-1a 256-bit hashing of a sample input, printing each hexadecimal digest.

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

namespace Cuemon.Security;

public class HashFactoryExample
{
    public void Demonstrate()
    {
        var fnvHash = HashFactory.CreateFnv32();
        var input = "Hello World";
        var hash = fnvHash.ComputeHash(Encoding.UTF8.GetBytes(input));
        Console.WriteLine($"FNV-1a 32-bit: {BitConverter.ToString(hash.To<byte[]>(bytes => bytes)).Replace("-", "")}");

        var crcHash = HashFactory.CreateCrc32();
        hash = crcHash.ComputeHash(Encoding.UTF8.GetBytes(input));
        Console.WriteLine($"CRC-32: {BitConverter.ToString(hash.To<byte[]>(bytes => bytes)).Replace("-", "")}");

        var fnv256Hash = HashFactory.CreateFnv256();
        hash = fnv256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
        Console.WriteLine($"FNV-1a 256-bit: {BitConverter.ToString(hash.To<byte[]>(bytes => bytes)).Replace("-", "")}");
    }
}

Methods

Name Description
CreateCrc(CyclicRedundancyCheckAlgorithm)

Creates an instance of a cyclic redundancy check implementation that derives from CyclicRedundancyCheck with the specified algorithm. Default is CyclicRedundancyCheck32 using Crc32.

CreateCrc32()

Creates an instance of CyclicRedundancyCheck32 using Crc32.

CreateCrc32(uint, uint, uint, Action<CyclicRedundancyCheckOptions>)

Creates an instance of CyclicRedundancyCheck32 from the specified arguments.

CreateCrc32Autosar()

Creates an instance of CyclicRedundancyCheck32 using Crc32Autosar.

CreateCrc32Bzip2()

Creates an instance of CyclicRedundancyCheck32 using Crc32Bzip2.

CreateCrc32C()

Creates an instance of CyclicRedundancyCheck32 using Crc32C.

CreateCrc32CdRomEdc()

Creates an instance of CyclicRedundancyCheck32 using Crc32CdRomEdc.

CreateCrc32D()

Creates an instance of CyclicRedundancyCheck32 using Crc32D.

CreateCrc32Jamcrc()

Creates an instance of CyclicRedundancyCheck32 using Crc32Jamcrc.

CreateCrc32Mpeg2()

Creates an instance of CyclicRedundancyCheck32 using Crc32Mpeg2.

CreateCrc32Posix()

Creates an instance of CyclicRedundancyCheck32 using Crc32Posix.

CreateCrc32Q()

Creates an instance of CyclicRedundancyCheck32 using Crc32Q.

CreateCrc32Xfer()

Creates an instance of CyclicRedundancyCheck32 using Crc32Xfer.

CreateCrc64()

Creates an instance of CyclicRedundancyCheck64 using Crc64.

CreateCrc64(ulong, ulong, ulong, Action<CyclicRedundancyCheckOptions>)

Creates an instance of CyclicRedundancyCheck64 from the specified arguments.

CreateCrc64GoIso()

Creates an instance of CyclicRedundancyCheck64 using Crc64GoIso.

CreateCrc64We()

Creates an instance of CyclicRedundancyCheck64 using Crc64We.

CreateCrc64Xz()

Creates an instance of CyclicRedundancyCheck64 using Crc64Xz.

CreateFnv(NonCryptoAlgorithm, Action<FowlerNollVoOptions>)

Creates an instance of a non-cryptographic implementation that derives from FowlerNollVoHash with the specified algorithm. Default is FowlerNollVo32 using Fnv1a.

CreateFnv1024(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo1024.

CreateFnv128(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo128.

CreateFnv256(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo256.

CreateFnv32(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo32.

CreateFnv512(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo512.

CreateFnv64(Action<FowlerNollVoOptions>)

Creates an instance of FowlerNollVo64.