Skip to main content
Table of Contents

Class ApiKeyFormat

Namespace
Stratara.Abstractions.ApiKeys
Assembly
Stratara.Abstractions.dll

The canonical raw-key format shared by every IApiKeyStore implementation: Prefix followed by the Base64Url encoding of 32 CSPRNG bytes. The prefix helps secret scanners flag leaked keys; the fixed length is what lets a store keep its stored digest unsalted.

public static class ApiKeyFormat
Inheritance
ApiKeyFormat
Inherited Members

Examples

Generate a key once and keep it in configuration:

var rawKey = ApiKeyFormat.CreateRawKey();   // stk_…

Remarks

Use CreateRawKey() whenever a key value has to exist before the store does — container orchestration, CI provisioning, or a self-hosted bundle where caller and server read the same key from configuration at start. Generate the value out of band, keep it in a secret store, and hand it to ImportAsync(ApiKeyImportRequest, CancellationToken) at boot. Never invent the value by hand: ImportAsync(ApiKeyImportRequest, CancellationToken) rejects anything that is not well-formed, because a low-entropy key would turn the store's unsalted digest into a guessable one.

This type lives in the abstractions package on purpose — the projects that need to generate a key (host builders, orchestration projects, test setups) usually do not reference the storage implementation.

Fields

Prefix

The prefix every raw key carries (stk_) — a stable marker for secret scanners.

public const string Prefix = "stk_"

Field Value

string

Methods

CreateRawKey()

Creates a new raw key: Prefix plus the Base64Url encoding of Stratara.Abstractions.ApiKeys.ApiKeyFormat.RandomByteCount cryptographically random bytes.

public static string CreateRawKey()

Returns

string

A well-formed raw key; treat it as a secret from the moment it exists.

IsWellFormed(string?)

Tests whether a value has the canonical shape — the prefix followed by exactly Stratara.Abstractions.ApiKeys.ApiKeyFormat.EncodedLength Base64Url characters.

public static bool IsWellFormed(string? rawKey)

Parameters

rawKey string

The candidate value.

Returns

bool

true when the value matches the canonical format.

Remarks

A shape check cannot prove that the bytes behind the value are random; it can only rule out values that are structurally incapable of carrying 256 bits. That is the point: values that pass came from a generator, values a human typed do not.