Activate a licence in .NET
In this guide
In a Windows desktop app, call Keyseal with a reusable HttpClient. The C# example checks signatures with native libsodium. Ship that library with your app for each target architecture.
To use the SDK, follow the client SDK integration guide.
Prepare the app
The file uses System.Net.Http.Json and DllImport in a modern .NET project. Set an HttpClient timeout, retain the fingerprint across updates and restrict licence storage to the app’s user. The functions below call the public API directly. Download DotNetLicence.cs.
Pin your organisation and product slugs (here atelier and dropsmith), the environment and its public keys in the build. The activation request sends the organisation and environment together. Obtain those keys at build time as described in the verification protocol. Keep management credentials and privileged calls on the publisher’s server.
Activate the first machine
Pass the key the buyer just typed and the local fingerprint to this function. Replace the sample machine name, platform, version and build date with your app’s values. A successful POST /v1/activate returns 200 with activation_id and certificate.
public static Task<HttpResponseMessage> Activate(HttpClient http, string key, string fingerprint) =>
http.PostAsJsonAsync(Api + "activate", new {
key, product = Product, fingerprint, machine_name = "Studio",
organization = "atelier", environment = "test",
platform = "windows", app_version = "1.0.0", build_date = "2026-11-17"
});
If every seat is taken (seats_exhausted), let the buyer release a machine. You can discard the entered key. Refresh sends activation_id, the original fingerprint and the current app_version.
Verify before granting access
Require two canonical base64url segments after keyseal:v1:. Read the kid from the UTF-8 JSON to select its pinned public key. Pass that key, the original payload segment as received and the 64 signature bytes to the function below. Load the native library from a trusted installation. Libsodium’s crypto_sign_verify_detached returns zero for a valid signature. If the library is unavailable or initialisation fails, keep licensed features disabled.
[DllImport("libsodium", CallingConvention = CallingConvention.Cdecl)]
private static extern int sodium_init();
[DllImport("libsodium", CallingConvention = CallingConvention.Cdecl)]
private static extern int crypto_sign_verify_detached(
byte[] signature, byte[] message, ulong length, byte[] publicKey);
public static bool ValidSignature(byte[] publicKey, string segment, byte[] signature)
{
if (publicKey.Length != 32 || signature.Length != 64 || sodium_init() < 0)
return false;
var message = Encoding.ASCII.GetBytes(segment);
return crypto_sign_verify_detached(signature, message, (ulong)message.Length, publicKey) == 0;
}
The signature is one step in the complete verification procedure. Check every signed claim, the expected product and the fingerprint’s SHA-256. Match act to the ID in the response, then replace the stored ID and certificate together. Run the protocol’s 19 vectors, including modified signatures and retired keys.
Start offline, refresh and release
Verify the stored certificate on every launch. When the network is unavailable, an active lease allows use. At or beyond lease_until, open preserves the last verified entitlements and closed blocks use until a successful refresh. For a 1.x build, check its release date and major with claims.CoversBuild(day, major: 1). A certificate with a signed update_major requires that exact major. If the claim is absent or null, historical date-based coverage still applies.
public static Task<HttpResponseMessage> Refresh(HttpClient http, string id, string fingerprint) =>
http.PostAsJsonAsync(Api + "refresh", new {
activation_id = id, fingerprint, app_version = "1.0.0"
});
public static Task<HttpResponseMessage> Deactivate(HttpClient http, string id, string fingerprint) =>
http.PostAsJsonAsync(Api + "deactivate", new { activation_id = id, fingerprint });
Call POST /v1/refresh in the background once a day when online. Verify a new certificate before replacing the previous one. Immediately persist a blocked state on revoked, suspended or expired, retain the ID and continue refreshing. For released, unknown_activation or wrong_machine, clear the activation and offer to activate again. A network failure or 429 preserves the previous state according to its lease.
The “Release this machine” action calls POST /v1/deactivate. On 204, clear the certificate and ID without reading a JSON body. An unknown activation or one belonging to a different machine can also be forgotten. On network failure, leave the release pending.