KZ.FileHash 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package KZ.FileHash --version 1.0.0
                    
NuGet\Install-Package KZ.FileHash -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KZ.FileHash" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KZ.FileHash" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="KZ.FileHash" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KZ.FileHash --version 1.0.0
                    
#r "nuget: KZ.FileHash, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KZ.FileHash@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KZ.FileHash&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=KZ.FileHash&version=1.0.0
                    
Install as a Cake Tool

KZ.FileHash

NuGet NuGet Downloads License

KZ.FileHash is a lightweight .NET library for calculating cryptographic hashes of files and streams asynchronously.

It is designed for applications that need reliable and memory-efficient file hashing without loading the entire file into memory.

The library supports multiple hashing algorithms, progress reporting, cancellation, file streams, and non-seekable streams.


Features

  • Calculate hashes asynchronously.
  • Calculate multiple hashes in a single read operation.
  • Supports files and streams.
  • Supports seekable and non-seekable streams.
  • Optional progress reporting from 0 to 100.
  • Supports CancellationToken.
  • Uses buffered asynchronous I/O.
  • Uses ArrayPool<byte> to reduce memory allocations.
  • Uses IncrementalHash for streaming hash calculation.
  • Does not load the entire file into memory.
  • Returns hexadecimal hash strings.
  • Supports combining multiple algorithms using [Flags].
  • Compatible with modern .NET applications.

Supported Algorithms

KZ.FileHash currently supports the following algorithms:

Algorithm Hex String Length
MD5 32
SHA-1 40
SHA-256 64
SHA-384 96
SHA-512 128
SHA3-256 64
SHA3-384 96
SHA3-512 128

Security note: MD5 and SHA-1 are considered cryptographically weak for security-sensitive applications. They are provided primarily for compatibility and integrity-checking scenarios where collision resistance is not a security requirement.


Installation

Install the package from NuGet:

dotnet add package KZ.FileHash

Quick Start

using KZ.FileHash.Engine;
using KZ.FileHash.Enums;

var engine = new FileHashEngine(HashAlgorithmType.SHA256);

var hashes = await engine.CalculateHashAsync("example.zip");

Console.WriteLine(hashes[HashAlgorithmType.SHA256]);

Multiple Algorithms

Multiple algorithms can be calculated in a single read operation:

var engine = new FileHashEngine(
    HashAlgorithmType.MD5 |
    HashAlgorithmType.SHA256 |
    HashAlgorithmType.SHA512);

var hashes = await engine.CalculateHashAsync("example.zip");

Console.WriteLine(hashes[HashAlgorithmType.MD5]);
Console.WriteLine(hashes[HashAlgorithmType.SHA256]);
Console.WriteLine(hashes[HashAlgorithmType.SHA512]);

Stream Support

KZ.FileHash also supports hashing directly from streams:

await using var stream = File.OpenRead("example.zip");

var engine = new FileHashEngine(HashAlgorithmType.SHA256);

var hashes = await engine.CalculateHashAsync(stream);

Console.WriteLine(hashes[HashAlgorithmType.SHA256]);

Progress Reporting

Progress reporting is optional:

var progress = new Progress<double>(value =>
{
    Console.WriteLine($"{value:F2}%");
});

var engine = new FileHashEngine(HashAlgorithmType.SHA256);

var hashes = await engine.CalculateHashAsync(
    "large-file.iso",
    progress);

Cancellation

Hash calculation supports cancellation through CancellationToken:

using var cts = new CancellationTokenSource();

var engine = new FileHashEngine(HashAlgorithmType.SHA256);

var hashes = await engine.CalculateHashAsync(
    "large-file.iso",
    cancellationToken: cts.Token);

AlgorithmsHelper

AlgorithmsHelper provides utilities for working with supported algorithms.

using KZ.FileHash.Enums;
using KZ.FileHash.Helpers;

var length =
    AlgorithmsHelper.GetAlgorithmHexStringLength(
        HashAlgorithmType.SHA256);

var algorithms =
    AlgorithmsHelper.GetAlgorithmsByLength(64);

var name =
    AlgorithmsHelper.GetAlgorithmName(
        HashAlgorithmType.SHA256);

Security Note

MD5 and SHA-1 are cryptographically weak and should not be used for security-sensitive applications.

They are included primarily for compatibility and non-security-critical integrity checking.

For modern applications, SHA-256, SHA-384, SHA-512, or SHA-3 variants are recommended.

License

KZ.FileHash is licensed under the MIT License.

See the LICENSE file for details.

Author

Kareem Zein

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 50 8/22/2026
1.0.0 56 8/19/2026