Skip to content

ApiKeyGenerator

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A helper that produces a raw API key value and its hash.

public static class ApiKeyGenerator

objectApiKeyGenerator

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Format: ap_{tenant-prefix}_{32-byte-base64url} The prefix exists only for READABILITY; it is not used for authentication — lookup always goes through the hash produced by ApiKeyGenerator.ComputeHash.

The hash algorithm is SHA-256, not Argon2. The key is a RANDOM 32-byte value, not a user password; a dictionary attack does not apply, and a slow hash would only add latency to every request.

Computes the SHA-256 hash of a raw key value.

public static byte[] ComputeHash(string plaintextKey)

plaintextKey string

The raw value.

byte[]

The 32-byte hash.

ArgumentException

plaintextKey is empty.

Generates a new raw key.

public static GeneratedApiKey Generate(string tenantId)

tenantId string

The tenant the key attaches to (read only for the prefix).

GeneratedApiKey

The raw value, its hash, and a display prefix.

ArgumentException

tenantId is empty.