Table of Contents

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

registry IEncryptionProviderRegistry

The encryption provider registry.

logger ILogger<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

options ReEncryptionOptions

Options specifying the scope of re-encryption.

cancellationToken CancellationToken

A 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

itemCount long

The number of items to re-encrypt.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<ReEncryptionEstimate>

An estimate of re-encryption work.

Type Parameters

T

The 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

entity T

The entity to re-encrypt.

context ReEncryptionContext

The re-encryption context.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<ReEncryptionResult>

The re-encryption result.

Type Parameters

T

The 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

entities IAsyncEnumerable<T>

The entities to re-encrypt.

options ReEncryptionOptions

Options controlling re-encryption behavior.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

IAsyncEnumerable<ReEncryptionResult<T>>

An async enumerable of re-encryption results.

Type Parameters

T

The entity type containing encrypted fields.

Remarks

Batch processing uses streaming for memory efficiency.

When ContinueOnError is true, failed items are yielded with Success = false.