Soenneker.Hashing.Pbkdf2
4.0.34
Prefix Reserved
dotnet add package Soenneker.Hashing.Pbkdf2 --version 4.0.34
NuGet\Install-Package Soenneker.Hashing.Pbkdf2 -Version 4.0.34
<PackageReference Include="Soenneker.Hashing.Pbkdf2" Version="4.0.34" />
<PackageVersion Include="Soenneker.Hashing.Pbkdf2" Version="4.0.34" />
<PackageReference Include="Soenneker.Hashing.Pbkdf2" />
paket add Soenneker.Hashing.Pbkdf2 --version 4.0.34
#r "nuget: Soenneker.Hashing.Pbkdf2, 4.0.34"
#:package Soenneker.Hashing.Pbkdf2@4.0.34
#addin nuget:?package=Soenneker.Hashing.Pbkdf2&version=4.0.34
#tool nuget:?package=Soenneker.Hashing.Pbkdf2&version=4.0.34
Soenneker.Hashing.Pbkdf2
Hashes secrets with PBKDF2-HMAC-SHA256 and encodes the iteration count, random salt, and derived hash in one record. It includes string convenience methods and span-first APIs for callers that want to control the output buffer.
Installation
dotnet add package Soenneker.Hashing.Pbkdf2
Hash and verify
using Soenneker.Hashing.Pbkdf2;
string storedHash = Pbkdf2HashingUtil.Hash(password);
bool valid = Pbkdf2HashingUtil.Verify(candidatePassword, storedHash);
Validate a stored record without deriving a hash:
bool validPhc = Pbkdf2HashingUtil.IsValidPhc(storedHash);
The encoded record has this format:
$pbkdf2-sha256$i=300000$<salt-base64>$<hash-base64>
Each hash gets a new cryptographically secure salt. The defaults are 300,000 iterations, a 16-byte salt, and a 32-byte derived hash.
Write into an existing character buffer
Span<char> destination = stackalloc char[128];
if (!Pbkdf2HashingUtil.TryHashToSpan(password, destination, out int written))
throw new InvalidOperationException("The destination was too small or the parameters were invalid.");
ReadOnlySpan<char> encoded = destination[..written];
TryHashToSpan() returns false and writes zero characters when the secret is empty, parameters are unsupported, or the destination cannot hold the complete record. Use Hash() when a final string is needed.
Work-factor limits
Custom values can be supplied to either hashing overload:
string storedHash = Pbkdf2HashingUtil.Hash(
password,
iterations: 600_000,
saltBytes: 24,
hashBytes: 32);
Supported records use 1–2,000,000 iterations, 8–64 salt bytes, and 16–128 derived bytes. These bounds prevent stored or attacker-controlled records from requesting unbounded CPU or buffer allocation. Hash() throws InvalidOperationException outside the bounds; TryHashToSpan() and Verify() return false.
Verification compares derived bytes in constant time and returns false for malformed, oversized, empty, or mismatched records. Sensitive temporary byte buffers are cleared before being returned to their pools. Applications should benchmark their chosen iteration count, rate-limit authentication, and avoid logging secrets or encoded records.
| Product | Versions 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. |
-
net10.0
- Soenneker.Hashing.Phc (>= 4.0.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Soenneker.Hashing.Pbkdf2:
| Package | Downloads |
|---|---|
|
Soenneker.Validators.BasicAuth
A lightweight validation module for validating HTTP Basic Authentication credentials. |
|
|
Soenneker.Validators.BasicAuth.Functions
A validation module for validating HTTP Basic Authentication credentials in Functions. |
|
|
Soenneker.Flywheel.Core
A durable background job processing, scheduling, and event execution runtime for .NET. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.34 | 0 | 9/7/2026 |
| 4.0.33 | 0 | 9/7/2026 |
| 4.0.32 | 0 | 9/6/2026 |
| 4.0.31 | 435 | 8/30/2026 |
| 4.0.30 | 351 | 8/29/2026 |
| 4.0.29 | 82 | 8/29/2026 |
| 4.0.28 | 1,416 | 7/28/2026 |
| 4.0.27 | 507 | 7/16/2026 |
| 4.0.26 | 1,066 | 6/19/2026 |
| 4.0.25 | 1,335 | 6/5/2026 |
| 4.0.24 | 131 | 6/5/2026 |
| 4.0.22 | 1,964 | 3/12/2026 |
| 4.0.21 | 152 | 3/12/2026 |
| 4.0.19 | 334 | 3/12/2026 |
| 4.0.18 | 584 | 3/10/2026 |
| 4.0.17 | 413 | 3/9/2026 |
| 4.0.16 | 127 | 3/9/2026 |
| 4.0.15 | 121 | 3/9/2026 |
| 4.0.14 | 633 | 3/4/2026 |
| 4.0.13 | 1,377 | 1/12/2026 |
Update dependency Soenneker.Hashing.Phc to 4.0.2 (#398)