Table of Contents

Class AesGcmEncryptionProvider

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

Provides AES-256-GCM authenticated encryption.

public sealed class AesGcmEncryptionProvider : IEncryptionProvider, IDisposable
Inheritance
AesGcmEncryptionProvider
Implements
Inherited Members

Remarks

This implementation uses .NET's AesGcm class which provides FIPS 140-2 compliant AES-GCM when running on a FIPS-enabled operating system.

Key characteristics:

  • 256-bit keys (32 bytes)
  • 96-bit nonces (12 bytes) - cryptographically random per operation
  • 128-bit authentication tags (16 bytes)
  • Support for associated authenticated data (AAD)

Constructors

AesGcmEncryptionProvider(IKeyManagementProvider, ILogger<AesGcmEncryptionProvider>, AesGcmEncryptionOptions?, IFipsDetector?)

Initializes a new instance of the AesGcmEncryptionProvider class.

public AesGcmEncryptionProvider(IKeyManagementProvider keyManagement, ILogger<AesGcmEncryptionProvider> logger, AesGcmEncryptionOptions? options = null, IFipsDetector? fipsDetector = null)

Parameters

keyManagement IKeyManagementProvider

The key management provider for key retrieval.

logger ILogger<AesGcmEncryptionProvider>

The logger for diagnostics.

options AesGcmEncryptionOptions

Optional configuration options.

fipsDetector IFipsDetector

Optional FIPS detector used to answer ValidateFipsComplianceAsync(CancellationToken). When omitted the provider uses the default detector, which inspects the host operating system.

Methods

DecryptAsync(EncryptedData, EncryptionContext, CancellationToken)

Decrypts ciphertext data using the embedded key metadata.

public Task<byte[]> DecryptAsync(EncryptedData encryptedData, EncryptionContext context, CancellationToken cancellationToken)

Parameters

encryptedData EncryptedData

The encrypted data including ciphertext and key metadata.

context EncryptionContext

The encryption context for tenant isolation and associated data verification. Must match the context used during encryption for AAD-bound ciphertexts.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<byte[]>

The decrypted plaintext data. A successful return is evidence that the ciphertext, key metadata and associated data are unmodified since encryption; see the authenticated-encryption requirement on IEncryptionProvider.

Exceptions

ArgumentNullException

Thrown when encryptedData is null.

EncryptionException

Thrown when decryption fails. Implementations MUST throw this when the ciphertext, the key metadata or the associated data has been modified, and MUST NOT return plaintext for modified input. Also thrown when the key cannot be found or the context does not match the one used during encryption.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

EncryptAsync(byte[], EncryptionContext, CancellationToken)

Encrypts plaintext data using the specified context.

public Task<EncryptedData> EncryptAsync(byte[] plaintext, EncryptionContext context, CancellationToken cancellationToken)

Parameters

plaintext byte[]

The data to encrypt.

context EncryptionContext

The encryption context providing key selection, tenant isolation, and associated data. Use Default for default settings.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<EncryptedData>

The encrypted data including ciphertext and metadata required for decryption.

Exceptions

ArgumentNullException

Thrown when plaintext is null.

EncryptionException

Thrown when encryption fails.

ValidateFipsComplianceAsync(CancellationToken)

Validates that the provider is configured for FIPS 140-2 compliant operations.

public Task<bool> ValidateFipsComplianceAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<bool>

True if FIPS 140-2 compliance is validated; otherwise, false.