Table of Contents

Class EncryptionContext

Namespace
Excalibur.Compliance
Assembly
Excalibur.Compliance.Abstractions.dll

Provides contextual information for encryption operations.

public sealed record EncryptionContext : IEquatable<EncryptionContext>
Inheritance
EncryptionContext
Implements
Inherited Members

Remarks

Encryption context includes tenant isolation, key selection, and associated authenticated data (AAD) for GCM mode.

Properties

Algorithm

Gets the encryption algorithm to use. If null, uses the provider's default algorithm.

public EncryptionAlgorithm? Algorithm { get; init; }

Property Value

EncryptionAlgorithm?

AssociatedData

Gets additional authenticated data (AAD) to bind with the ciphertext. AAD is authenticated but not encrypted; tampering is detected on decryption.

public byte[]? AssociatedData { get; init; }

Property Value

byte[]

Classification

Gets the data classification level for the data being encrypted. Used for policy enforcement and audit.

public DataClassification? Classification { get; init; }

Property Value

DataClassification?

Default

Creates a minimal context with default settings.

public static EncryptionContext Default { get; }

Property Value

EncryptionContext

KeyGeneration

Gets the key GENERATION this operation is bound to, or null when the caller does not identify one.

public string? KeyGeneration { get; init; }

Property Value

string

Remarks

This is the single source of the generation on BOTH the write and the read path, and that is what makes it safe. An encryption provider reads the generation from here and nowhere else — never from key metadata on the write path — so a caller that supplies no generation binds none on either side and is unaffected, while a caller that supplies one binds it symmetrically. Sourcing it from metadata when writing and from the payload when reading would bind a value on one side and nothing on the other, and every such payload would fail to authenticate immediately.

When present it is included in the authenticated associated data, so a payload cannot be re-attributed to a different generation of the same key handle without failing to authenticate.

KeyId

Gets the identifier for the key to use. If null, the provider selects the default active key.

public string? KeyId { get; init; }

Property Value

string

KeyVersion

Gets the specific key version to use. If null, uses the latest version. Required for decryption when multiple key versions exist.

public int? KeyVersion { get; init; }

Property Value

int?

Purpose

Gets the purpose of this encryption operation (e.g., "pii-field", "message-payload"). Used for audit logging and key selection policies.

public string? Purpose { get; init; }

Property Value

string

RequireFipsCompliance

Gets a value indicating whether FIPS 140-2 compliance is required for this operation.

public bool RequireFipsCompliance { get; init; }

Property Value

bool

TenantId

Gets the tenant identifier for multi-tenant isolation. Ensures cryptographic separation between tenants.

public string? TenantId { get; init; }

Property Value

string

Methods

ForTenant(string)

Creates a context for a specific tenant.

public static EncryptionContext ForTenant(string tenantId)

Parameters

tenantId string

The tenant identifier.

Returns

EncryptionContext

An encryption context configured for the tenant.