Table of Contents

Class AesGcmEnvelope

Namespace
MailFathom.Common
Assembly
MailFathom.Common.dll

Seals a value with AES-256-GCM so that reading where it is stored does not disclose it.

public static class AesGcmEnvelope
Inheritance
AesGcmEnvelope
Inherited Members

Remarks

The sealed form is nonce ‖ tag ‖ ciphertext: a fresh 96-bit nonce, the 128-bit authentication tag, and the ciphertext, in that order and in one buffer. The layout is fixed rather than configurable, because a reader has to be able to open a value written by an older build.

Every operation takes associated data, which is authenticated but not encrypted. It is what binds a sealed value to where it belongs — a credential to its endpoint, a column value to its row — so a value moved somewhere else fails to open instead of quietly decrypting under the wrong meaning. There is no overload without it: a caller with nothing to bind is a caller who has not yet worked out what the value is for.

This type holds no key. It is handed one and forgets it, which is deliberate: where a key comes from, how long it lives, and what protects it at rest differ per consumer, and folding a single answer in here would give two consumers with different threat models the weaker of the two.

Fields

KeySizeInBytes

The key length this envelope uses, in bytes.

Methods

CreateKey()

Generates a key of the length this envelope expects.

Open(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Opens a sealed value.

OpenText(ReadOnlySpan<byte>, string, string)

Opens text sealed by SealText(ReadOnlySpan<byte>, string, string).

Seal(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Seals a value.

SealText(ReadOnlySpan<byte>, string, string)

Seals text into a form that can be written where only text fits.