WatermarkKey

Models & Types · AiDotNet.Safety.Watermarking

The secret key of a keyed watermark, and the pseudo-random values every keyed watermarker derives from it.

For Beginners

the key works like a password. Whoever embeds a watermark and whoever later checks for it must use the same key. Keep it secret and never use the public key for content you need to prove is yours; a long random value, such as 32 random bytes written in base64, is a good key.

How It Works

Every keyed watermarker in this namespace (text, audio and image) derives its watermark from the key through HMAC-SHA256, so the key is the whole secret: without it the pattern cannot be predicted, removed on purpose or forged, and a detector holding a different key sees only noise. Two derivations are offered:

A key is created from a string. Public is a key whose text is published in this library: anyone can reproduce, and therefore forge, a watermark made with it. It exists so that a watermarker constructed without a key is deterministic (it never draws a random key that nobody can later detect with); an application marking its own content must use a secret key of its own, and RequireSecret turns a missing or public key into a configuration error.

Constructors

Constructor Summary
WatermarkKey(string key) Creates a key from its text.

Properties

Property Summary
WatermarkKey Public { get; } The published key, used by watermarkers constructed without a key.
bool IsPublic { get; } Whether this is the published Public key, whose marks anyone can forge.

Methods

Method Summary
WatermarkKey FromOptional(string key) The key for key, or Public when it is null.
WatermarkKey RequireSecret(string key, string settingName) The key for a setting that must hold a secret key of the application’s own.
double Uniform(ulong seed, int item) A uniform value in [0, 1) for item under seed: the SplitMix64 finalizer of seed + item * golden-ratio increment, top 53 bits.
double[] SignPattern(int salt, int stream, int count) The key’s +/-1 pattern for one stream: the bits of HMAC-SHA256(key, salt || stream || block), 256 per block, least significant bit first; a 0 bit is -1.
ulong Seed(int salt, IReadOnlyList<int> values) A 64-bit pseudo-random seed for one context: the first eight bytes (little-endian) of HMAC-SHA256(key, salt || values[0] || values[1] || …).

Fields

Field Summary
string PublicKeyText The text of Public.