Table of Contents

Class HkdfKeyDeriver

Namespace
Excalibur.Compliance.Encryption
Assembly
Excalibur.Compliance.dll

Derives child keys from a master key using HKDF (RFC 5869).

public sealed class HkdfKeyDeriver
Inheritance
HkdfKeyDeriver
Inherited Members

Remarks

HKDF is used for deriving multiple cryptographically strong keys from a single master key. Unlike PBKDF2 (which derives keys from passwords), HKDF is designed for already-strong key material and is suitable for:

  • Deriving per-message encryption keys
  • Deriving per-tenant keys from a master key
  • Creating key hierarchies (master to purpose-specific subkeys)

Constructors

HkdfKeyDeriver(IOptions<HkdfKeyDerivationOptions>)

Initializes a new instance of the HkdfKeyDeriver class.

public HkdfKeyDeriver(IOptions<HkdfKeyDerivationOptions> options)

Parameters

options IOptions<HkdfKeyDerivationOptions>

The HKDF key derivation options.

Methods

DeriveKey(byte[], string)

Derives a key for a specific purpose without additional context.

public byte[] DeriveKey(byte[] masterKey, string purpose)

Parameters

masterKey byte[]

The master key material to derive from.

purpose string

The purpose identifier for key separation (e.g., "field-encryption", "tenant-key").

Returns

byte[]

The derived key bytes.

Exceptions

ArgumentNullException

Thrown when masterKey or purpose is null.

ArgumentException

Thrown when masterKey is empty or purpose is whitespace.

DeriveKey(byte[], string, ReadOnlySpan<byte>)

Derives a key for a specific purpose and context.

public byte[] DeriveKey(byte[] masterKey, string purpose, ReadOnlySpan<byte> context)

Parameters

masterKey byte[]

The master key material to derive from.

purpose string

The purpose identifier for key separation (e.g., "field-encryption", "tenant-key").

context ReadOnlySpan<byte>

Additional context bytes for key derivation (e.g., tenant ID, message ID).

Returns

byte[]

The derived key bytes.

Exceptions

ArgumentNullException

Thrown when masterKey or purpose is null.

ArgumentException

Thrown when masterKey is empty or purpose is whitespace.