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
keyManagementIKeyManagementProviderThe key management provider for key retrieval.
loggerILogger<AesGcmEncryptionProvider>The logger for diagnostics.
optionsAesGcmEncryptionOptionsOptional configuration options.
fipsDetectorIFipsDetectorOptional 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
encryptedDataEncryptedDataThe encrypted data including ciphertext and key metadata.
contextEncryptionContextThe encryption context for tenant isolation and associated data verification. Must match the context used during encryption for AAD-bound ciphertexts.
cancellationTokenCancellationTokenA 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
encryptedDatais 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
plaintextbyte[]The data to encrypt.
contextEncryptionContextThe encryption context providing key selection, tenant isolation, and associated data. Use Default for default settings.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<EncryptedData>
The encrypted data including ciphertext and metadata required for decryption.
Exceptions
- ArgumentNullException
Thrown when
plaintextis 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
cancellationTokenCancellationTokenA token to cancel the operation.