Soenneker.Hashing.Sha256
11.0.21
Prefix Reserved
dotnet add package Soenneker.Hashing.Sha256 --version 11.0.21
NuGet\Install-Package Soenneker.Hashing.Sha256 -Version 11.0.21
<PackageReference Include="Soenneker.Hashing.Sha256" Version="11.0.21" />
<PackageVersion Include="Soenneker.Hashing.Sha256" Version="11.0.21" />
<PackageReference Include="Soenneker.Hashing.Sha256" />
paket add Soenneker.Hashing.Sha256 --version 11.0.21
#r "nuget: Soenneker.Hashing.Sha256, 11.0.21"
#:package Soenneker.Hashing.Sha256@11.0.21
#addin nuget:?package=Soenneker.Hashing.Sha256&version=11.0.21
#tool nuget:?package=Soenneker.Hashing.Sha256&version=11.0.21
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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Hashing.Sha256:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.Spans.Readonly.Bytes
A collection of helpful ReadOnlySpan (byte) extension methods |
|
|
Soenneker.Aws.Signing.V4
A dependency-free .NET implementation of AWS Signature Version 4 request signing. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.21 | 12,757 | 11/11/2026 |
| 11.0.20 | 93,072 | 11/3/2026 |
| 4.0.17 | 38,526 | 10/26/2026 |
| 4.0.16 | 162,064 | 10/14/2026 |
| 4.0.15 | 432 | 10/14/2026 |
| 4.0.9 | 2,867 | 10/12/2026 |
| 4.0.8 | 5,897 | 10/12/2026 |
| 4.0.7 | 41,887 | 10/11/2026 |
| 4.0.6 | 237,267 | 9/24/2026 |
| 4.0.5 | 98,049 | 9/15/2026 |
| 4.0.4 | 79,705 | 9/12/2026 |
| 4.0.3 | 75,839 | 9/8/2026 |
| 4.0.2 | 62,753 | 9/7/2026 |
| 4.0.1 | 94,662 | 9/4/2026 |
Upgrade .NET 11 release candidates to stable