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
optionsIOptions<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
masterKeybyte[]The master key material to derive from.
purposestringThe purpose identifier for key separation (e.g., "field-encryption", "tenant-key").
Returns
- byte[]
The derived key bytes.
Exceptions
- ArgumentNullException
Thrown when
masterKeyorpurposeis null.- ArgumentException
Thrown when
masterKeyis empty orpurposeis 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
masterKeybyte[]The master key material to derive from.
purposestringThe purpose identifier for key separation (e.g., "field-encryption", "tenant-key").
contextReadOnlySpan<byte>Additional context bytes for key derivation (e.g., tenant ID, message ID).
Returns
- byte[]
The derived key bytes.
Exceptions
- ArgumentNullException
Thrown when
masterKeyorpurposeis null.- ArgumentException
Thrown when
masterKeyis empty orpurposeis whitespace.