Class ReEncryptionService
- Namespace
- Excalibur.Compliance.Encryption
- Assembly
- Excalibur.Compliance.dll
Provides re-encryption services for key rotation and algorithm migration.
public sealed class ReEncryptionService : IReEncryptionService
- Inheritance
-
ReEncryptionService
- Implements
- Inherited Members
Remarks
This service uses IEncryptionProviderRegistry for provider lookup, decrypting with the source provider and encrypting with the target provider.
Constructors
ReEncryptionService(IEncryptionProviderRegistry, ILogger<ReEncryptionService>)
Initializes a new instance of the ReEncryptionService class.
public ReEncryptionService(IEncryptionProviderRegistry registry, ILogger<ReEncryptionService> logger)
Parameters
registryIEncryptionProviderRegistryThe encryption provider registry.
loggerILogger<ReEncryptionService>The logger for diagnostics.
Methods
EstimateAsync(ReEncryptionOptions, CancellationToken)
Estimates the work required for a re-encryption operation.
public Task<ReEncryptionEstimate> EstimateAsync(ReEncryptionOptions options, CancellationToken cancellationToken)
Parameters
optionsReEncryptionOptionsOptions specifying the scope of re-encryption.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<ReEncryptionEstimate>
An estimate of the re-encryption work.
Remarks
Use this method for planning and progress tracking before executing ReEncryptBatchAsync<T>(IAsyncEnumerable<T>, ReEncryptionOptions, CancellationToken).
EstimateForTypeAsync<T>(long, CancellationToken)
Estimates re-encryption work for a specific entity type with known item count.
public Task<ReEncryptionEstimate> EstimateForTypeAsync<T>(long itemCount, CancellationToken cancellationToken) where T : class
Parameters
itemCountlongThe number of items to re-encrypt.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<ReEncryptionEstimate>
An estimate of re-encryption work.
Type Parameters
TThe entity type containing encrypted fields.
Remarks
Estimation uses the following formula:
- Re-encryption time: ~5ms per field (decrypt + encrypt with AES-256-GCM)
- I/O overhead: 20% buffer added to computed duration
ReEncryptAsync<T>(T, ReEncryptionContext, CancellationToken)
Re-encrypts a single entity with a new provider.
public Task<ReEncryptionResult> ReEncryptAsync<T>(T entity, ReEncryptionContext context, CancellationToken cancellationToken) where T : class
Parameters
entityTThe entity to re-encrypt.
contextReEncryptionContextThe re-encryption context.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<ReEncryptionResult>
The re-encryption result.
Type Parameters
TThe entity type containing encrypted fields.
Remarks
Fields marked with EncryptedFieldAttribute are decrypted with the source provider and re-encrypted with the target provider.
ReEncryptBatchAsync<T>(IAsyncEnumerable<T>, ReEncryptionOptions, CancellationToken)
Re-encrypts a batch of entities with a new provider using streaming.
public IAsyncEnumerable<ReEncryptionResult<T>> ReEncryptBatchAsync<T>(IAsyncEnumerable<T> entities, ReEncryptionOptions options, CancellationToken cancellationToken) where T : class
Parameters
entitiesIAsyncEnumerable<T>The entities to re-encrypt.
optionsReEncryptionOptionsOptions controlling re-encryption behavior.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- IAsyncEnumerable<ReEncryptionResult<T>>
An async enumerable of re-encryption results.
Type Parameters
TThe entity type containing encrypted fields.
Remarks
Batch processing uses streaming for memory efficiency.
When ContinueOnError is true,
failed items are yielded with Success = false.