Table of Contents

IHashAlgorithmFactory<T> Interface

Definition

Namespace
Bodu.Security.Cryptography
Assembly
Bodu.Security.Cryptography.dll
Package
Bodu.Security.Cryptography 1.3.0
Source
IHashAlgorithmFactory{T}.cs

Defines a factory that produces configured instances of a specific HashAlgorithm implementation.

public interface IHashAlgorithmFactory<out T> where T : HashAlgorithm

Type Parameters

T

The concrete type of HashAlgorithm this factory creates.

Extension Methods

Remarks

This interface decouples the creation and configuration of hash algorithm instances from the logic that consumes them, enabling reusable, testable, and extensible one-shot hash operations via the HashAlgorithmHelper utility class. Each call to Create() must return a new instance that the caller owns and disposes: HashAlgorithmHelper disposes every instance it creates, and MerkleTree requires a fresh one, so do not return pooled or shared instances.

How to obtain an instance. Most callers do not implement this interface directly. Use From<T>(Func<T>) to wrap an algorithm-construction delegate as a DelegateHashAlgorithmFactory<T> - the right pick whenever the algorithm needs configuration (a key, a round count, a variant flag) at the construction site. Implement IHashAlgorithmFactory<T> directly only when adding telemetry or other cross-cutting behavior around algorithm creation.

How it is consumed. Pass the factory to the static helpers on HashAlgorithmHelper, or its Create() method to MerkleTree. Each call gets a fresh, fully configured algorithm instance - the callers do not need to manage IDisposable lifecycles or thread-safety.

The type argument T must derive from HashAlgorithm.

Methods

Create()

Creates and returns a new instance of the hash algorithm with any necessary configuration applied.

T Create()

Returns

T

A fully initialized T instance, ready for data input.

Applies to

ProductVersions
.NET8, 10

See Also