Soenneker.Hashing.Sha256 4.0.1

Prefix Reserved
dotnet add package Soenneker.Hashing.Sha256 --version 4.0.1
                    
NuGet\Install-Package Soenneker.Hashing.Sha256 -Version 4.0.1
                    
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="Soenneker.Hashing.Sha256" Version="4.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Hashing.Sha256" Version="4.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Hashing.Sha256" />
                    
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 Soenneker.Hashing.Sha256 --version 4.0.1
                    
#r "nuget: Soenneker.Hashing.Sha256, 4.0.1"
                    
#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 Soenneker.Hashing.Sha256@4.0.1
                    
#: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=Soenneker.Hashing.Sha256&version=4.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Hashing.Sha256&version=4.0.1
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Hashing.Sha256

Fast, dependency-light SHA-256 hashing and constant-time verification for bytes, UTF-8 text, streams, and files.

Results returned as text are canonical 64-character lowercase hexadecimal strings. Hexadecimal verification accepts either casing.

SHA-256 is designed for content integrity, fingerprints, and deterministic identifiers. It is not suitable for password storage; use a password-hashing algorithm such as Argon2id, bcrypt, or PBKDF2 instead.

Installation

dotnet add package Soenneker.Hashing.Sha256

Registration

services.AddSha256HashingUtilAsSingleton();

Scoped registration is also available through AddSha256HashingUtilAsScoped().

Text and bytes

ISha256HashingUtil sha256 = serviceProvider.GetRequiredService<ISha256HashingUtil>();

string textHash = sha256.Hash("hello world");
string bytesHash = sha256.HashToString("hello world"u8);

Span<byte> digest = stackalloc byte[32];
sha256.TryHash("hello world"u8, digest, out int bytesWritten);

Text is always encoded as UTF-8 without a byte-order mark.

Verification

string expected = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";

bool matches = sha256.Verify("hello world", expected);

Digest comparison uses CryptographicOperations.FixedTimeEquals.

Streams and files

string fileHash = await sha256.HashFile("archive.zip", cancellationToken);
bool fileMatches = await sha256.VerifyFile("archive.zip", expectedHash, cancellationToken);

await using Stream stream = File.OpenRead("archive.zip");
byte[] digest = await sha256.Hash(stream, cancellationToken);

Stream hashing begins at the stream's current position and consumes it through the end. Streams supplied by the caller are not disposed.

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.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on Soenneker.Hashing.Sha256:

Package Downloads
Soenneker.Extensions.Spans.Readonly.Bytes

A collection of helpful ReadOnlySpan (byte) extension methods

Soenneker.Cosmos.Client

A utility library for Azure Cosmos client accessibility

Soenneker.Cosmos.Database

A utility library for storing Azure Cosmos databases

Soenneker.Cosmos.Container

A utility library for storing Azure Cosmos containers

Soenneker.Cloudflare.HttpClient

An async thread-safe HttpClient singleton for the Cloudflare API

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1 15,704 9/4/2026