Table of Contents

Class UnkeyedHashFactory

Namespace
Cuemon.Security.Cryptography
Assembly
Cuemon.Security.Cryptography.dll

Provides access to factory methods for creating and configuring Hash instances based on UnkeyedCryptoHash<TAlgorithm>.

public static class UnkeyedHashFactory
Inheritance
UnkeyedHashFactory

Examples

The following example demonstrates how to compute SHA-256 and SHA-512 hashes for data integrity using UnkeyedHashFactory. It hashes a sample input and prints the hexadecimal digest for each algorithm.

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

namespace Cuemon.Security.Cryptography;

public class UnkeyedHashFactoryExample
{
    public void Demonstrate()
    {
        var sha256 = UnkeyedHashFactory.CreateCryptoSha256();
        var input = "Data to hash";
        var hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(input));
        Console.WriteLine($"SHA-256: {BitConverter.ToString(hash.GetBytes()).Replace("-", "")}");

        var sha512 = UnkeyedHashFactory.CreateCryptoSha512();
        hash = sha512.ComputeHash(Encoding.UTF8.GetBytes(input));
        Console.WriteLine($"SHA-512: {BitConverter.ToString(hash.GetBytes()).Replace("-", "")}");
    }
}

Methods

CreateCrypto(UnkeyedCryptoAlgorithm, Action<ConvertibleOptions>)

Creates an instance of a cryptographic implementation that derives from UnkeyedCryptoHash<TAlgorithm> with the specified algorithm. Default is SecureHashAlgorithm256.

public static Hash CreateCrypto(UnkeyedCryptoAlgorithm algorithm = UnkeyedCryptoAlgorithm.Sha256, Action<ConvertibleOptions> setup = null)

Parameters

algorithm UnkeyedCryptoAlgorithm

The UnkeyedCryptoAlgorithm that defines the cryptographic implementation. Default is Sha256.

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of the by parameter specified algorithm.

CreateCryptoMd5(Action<ConvertibleOptions>)

Creates an instance of MessageDigest5.

public static Hash CreateCryptoMd5(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of MessageDigest5.

CreateCryptoSha1(Action<ConvertibleOptions>)

Creates an instance of SecureHashAlgorithm1.

public static Hash CreateCryptoSha1(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of SecureHashAlgorithm1.

CreateCryptoSha256(Action<ConvertibleOptions>)

Creates an instance of SecureHashAlgorithm256.

public static Hash CreateCryptoSha256(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of SecureHashAlgorithm256.

CreateCryptoSha384(Action<ConvertibleOptions>)

Creates an instance of SecureHashAlgorithm384.

public static Hash CreateCryptoSha384(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of SecureHashAlgorithm384.

CreateCryptoSha512(Action<ConvertibleOptions>)

Creates an instance of SecureHashAlgorithm512.

public static Hash CreateCryptoSha512(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of SecureHashAlgorithm512.

CreateCryptoSha512Slash256(Action<ConvertibleOptions>)

Creates an instance of SecureHashAlgorithm512256.

public static Hash CreateCryptoSha512Slash256(Action<ConvertibleOptions> setup = null)

Parameters

setup Action<ConvertibleOptions>

The ConvertibleOptions which may be configured.

Returns

Hash

A Hash implementation of SecureHashAlgorithm512256.