Class EncryptionDecryptionService
- Namespace
- Excalibur.Compliance.Encryption
- Assembly
- Excalibur.Compliance.dll
Provides bulk decryption services for compliance scenarios.
public sealed class EncryptionDecryptionService : IEncryptionDecryptionService
- Inheritance
-
EncryptionDecryptionService
- Implements
- Inherited Members
Remarks
This service uses streaming (IAsyncEnumerable) for memory efficiency when processing large datasets for GDPR, audit, or data export requirements.
Constructors
EncryptionDecryptionService(IEncryptionProviderRegistry, IOptions<EncryptionOptions>, ITenantContext, ILogger<EncryptionDecryptionService>)
Initializes a new instance of the EncryptionDecryptionService class.
public EncryptionDecryptionService(IEncryptionProviderRegistry registry, IOptions<EncryptionOptions> options, ITenantContext tenantContext, ILogger<EncryptionDecryptionService> logger)
Parameters
registryIEncryptionProviderRegistryThe encryption provider registry.
optionsIOptions<EncryptionOptions>The encryption configuration options.
tenantContextITenantContextResolves the tenant of the operation in flight, so the tenant bound into the authenticated data is the tenant of the data rather than a process-wide constant. A caller decrypting records that belong to a different tenant than the ambient one supplies Context instead.
loggerILogger<EncryptionDecryptionService>The logger for diagnostics.
Methods
DecryptAllAsync<T>(IAsyncEnumerable<T>, DecryptionOptions, CancellationToken)
Decrypts all encrypted fields in a collection using streaming for memory efficiency.
public IAsyncEnumerable<T> DecryptAllAsync<T>(IAsyncEnumerable<T> source, DecryptionOptions options, CancellationToken cancellationToken) where T : class
Parameters
sourceIAsyncEnumerable<T>The source collection of entities to decrypt.
optionsDecryptionOptionsOptions controlling decryption behavior.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- IAsyncEnumerable<T>
An async enumerable of decrypted entities.
Type Parameters
TThe entity type containing encrypted fields.
Remarks
Entities are processed in batches (per BatchSize) and yielded as they are decrypted to minimize memory usage.
Fields marked with EncryptedFieldAttribute are decrypted; other fields are passed through unchanged.
DecryptEntityAsync<T>(T, DecryptionOptions, CancellationToken)
Decrypts encrypted fields in a single entity.
public Task<T> DecryptEntityAsync<T>(T entity, DecryptionOptions options, CancellationToken cancellationToken) where T : class
Parameters
entityTThe entity to decrypt.
optionsDecryptionOptionsOptions controlling decryption behavior.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<T>
The decrypted entity (same instance with fields decrypted).
Type Parameters
TThe entity type containing encrypted fields.
Remarks
Fields marked with EncryptedFieldAttribute are decrypted in place.
ExportDecryptedAsync<T>(IAsyncEnumerable<T>, BulkDecryptionExportOptions, CancellationToken)
Exports decrypted data to a stream for compliance purposes.
[RequiresUnreferencedCode("Exporting decrypted data uses JSON serialization for generic types which requires preserved members.")]
[RequiresDynamicCode("Exporting decrypted data uses JSON serialization for generic types which requires dynamic code generation.")]
public Task ExportDecryptedAsync<T>(IAsyncEnumerable<T> source, BulkDecryptionExportOptions options, CancellationToken cancellationToken) where T : class
Parameters
sourceIAsyncEnumerable<T>The source collection of entities to decrypt and export.
optionsBulkDecryptionExportOptionsOptions controlling export behavior.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task
A task representing the export operation.
Type Parameters
TThe entity type to export.
Remarks
Supports multiple export formats (JSON, CSV, Plaintext) for compliance flexibility.
Data is streamed to the destination to support large exports without loading the entire dataset into memory.