Skip to content
Tracon

IContentProtector

Namespace Tracon · Assembly Tracon.Abstractions.dll

Extension point for at-rest encryption of stored content.

public interface IContentProtector

There is no default implementation; a consumer opts in explicitly through AddContentProtection. When nothing is registered, the stores that consume this interface fall back to a no-op implementation that writes plaintext unchanged — today’s behavior, with no surprises.

This protects data at rest, not a running process. A process holding the key still sees plaintext once a value is read back; this interface addresses a stolen backup, a discarded disk, or a misconfigured table permission — not a compromised application server.

IContentProtector.Unprotect and IContentProtector.UnprotectBytes are self-describing: they decide whether a value is protected by looking at the value itself, not at configuration. A value written before protection was turned on therefore stays readable after protection is turned on, and a value written while protection was on stays readable after it is turned off.

Gets a value indicating whether this instance is ready to protect new writes.

bool IsEnabled { get; }

bool

A column-level decision (which columns are in scope) is layered on top of this by the caller; this flag only says whether the implementation itself has everything it needs (for example, a resolved encryption key).

Protects a text value before it is written to storage.

string Protect(string plaintext)

plaintext string

The value to protect.

string

The protected representation. It must be safe to store in the same column the plaintext would have gone into.

Protects binary data before it is written to storage.

byte[] ProtectBytes(ReadOnlySpan<byte> plaintext)

plaintext ReadOnlySpan<byte>

The bytes to protect.

byte[]

The protected representation. It must be safe to store in the same column the plaintext would have gone into.

Reverses IContentProtector.Protect.

string Unprotect(string stored)

stored string

The value as read back from storage.

string

The original plaintext. When stored was never protected, it is returned unchanged.

Reverses IContentProtector.ProtectBytes.

byte[] UnprotectBytes(ReadOnlySpan<byte> stored)

stored ReadOnlySpan<byte>

The bytes as read back from storage.

byte[]

The original bytes. When stored was never protected, it is returned unchanged.