Class RecoveryCodePepperProvider

Assembly: redb.Identity.Core.dll

Provides the server-wide pepper applied during MFA recovery-code hashing
(B4 — defence-in-depth on top of per-user salt + PBKDF2) and to the hashes of the
password-reset, e-mail-verification and change-e-mail tokens.

The current pepper () hashes everything new; the previous ones
() are only tried on verification, so a rotation keeps
what was issued under them. Every pepper has an id () that stored hashes record, so a
record is checked against exactly its pepper.

Singleton lifetime: pepper bytes are decoded once at construction so every
instance shares the same value.

public sealed class RecoveryCodePepperProvider

Inheritance

Object→RecoveryCodePepperProvider

Properties

IsEphemeral

True if the pepper was generated at startup (development fallback).

public bool IsEphemeral { get; }

Pepper

Raw pepper bytes (configured or ephemeral). Never empty.

public byte[] Pepper { get; }

PepperId

Id of the current pepper, recorded with every hash made from it.

public string PepperId { get; }

PreviousPepperIds

Ids of the previous peppers, in configured order.

public IReadOnlyList<string> PreviousPepperIds { get; }

Methods

ComputeId(byte[])

The id of a pepper: the first 8 bytes of HMAC-SHA256(pepper, "redb.identity.pepper-id"), lowercase hex. It

public static string ComputeId(byte[] pepper)

ForTesting(byte[]?, params byte[][])

Test-only factory: builds a provider with a fixed (or random 32-byte) pepper, and optional previous peppers,

public static RecoveryCodePepperProvider ForTesting(byte[]? pepper = null, params byte[][] previous)

MatchesTokenHash(string, string, string?)

Checks a one-time link token against its stored hash with the peppers gives for the

public bool MatchesTokenHash(string token, string storedHash, string? pepperId)

PepperedSha256Hex(byte[], string)

sha256(pepper || token), lowercase hex: the stored form of the one-time link tokens.

public static string PepperedSha256Hex(byte[] pepper, string token)

PeppersFor(string?)

The peppers a stored hash is checked against. A hash with an id gets exactly its pepper, or none when that

public IReadOnlyList<byte[]> PeppersFor(string? pepperId)

Constructors