IHashAlgorithmFactory<T> Interface
Definition
- Namespace
- Bodu.Security.Cryptography
- Assembly
- Bodu.Security.Cryptography.dll
- Package
- Bodu.Security.Cryptography 1.3.0
Defines a factory that produces configured instances of a specific HashAlgorithm implementation.
public interface IHashAlgorithmFactory<out T> where T : HashAlgorithm
Type Parameters
TThe 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
Tinstance, ready for data input.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |