From a package to a licensed operation in an afternoon.
The SDK verifies signed leases on the device and answers every check from memory, with no network call. Your code asks one question at the operation it protects: is this entitlement granted?
Activate once, then check where the work happens.
The package targets .NET 10 and is safe for trimmed and NativeAOT builds: it uses source-generated JSON and no reflection. State is protected with DPAPI on Windows, the Secret Service on Linux, and an owner-only key file elsewhere.
dotnet add package Kleis.Clientusing Kleis.Client;
var options = new KleisClientOptions
{
ServerUrl = new Uri("https://licensing.example.com/"),
TenantId = Guid.Parse("..."),
ProductId = Guid.Parse("..."),
ClientVersion = "2.4.0",
};
options.TrustedRootKeys.Add(new TrustedRootKey { KeyId = "root-2027", PublicKey = "..." });
await using var kleis = new KleisClient(options);var result = await kleis.ActivateAsync(licenseKeyFromUser);
if (!result.Succeeded)
{
ShowMessage(result.Reason, result.Recovery, result.Message);
}public void ExportPdf(Document document)
{
var decision = kleis.CheckEntitlement("export.pdf");
if (!decision.Granted)
{
throw new LicenseDeniedException(decision.Reason, decision.Recovery);
}
// ... export ...
}await kleis.StartAsync();
kleis.StatusChanged += (_, snapshot) => RefreshUi(snapshot);var reservation = await kleis.ReserveUsageAsync("usage.reportCredits", 1);
if (!reservation.Granted)
{
Explain(reservation.Reason, reservation.Recovery);
return;
}
var used = GenerateReport() ? 1 : 0;
await kleis.ReportUsageAsync(reservation, used);A hosted service, a health check, and authorization by entitlement.
For software you ship as a server: the integration keeps the lease current in the background, reports licensing in your health endpoint, and lets a policy name the entitlement an endpoint needs.
builder.Services
.AddKleisClient(builder.Configuration.GetSection("Kleis"))
.AddKleisHostedValidation()
.AddKleisHealthCheck()
.AddKleisAuthorization();app.MapPost("/reports/advanced", GenerateReport).RequireAuthorization("Kleis:reports.advanced");
[RequireEntitlement("export.pdf")]
public IActionResult Export() { ... }C and C++, through a stable C interface.
The native client is C++20 behind a C interface, built with CMake and vcpkg, and tested on Windows and Linux against the same protocol fixtures as the C# SDK. It covers activation, validation, entitlement checks, metered usage, retries, and the air-gapped exchange. It has no live notification channel: it learns of changes at its next heartbeat.
#include "KleisClient/kleis_client.h"
kleis_root_key root = { "root-2026", "<base64url public key>" };
kleis_client_options options;
kleis_client_options_init(&options);
options.server_url = "https://licensing.example.com";
options.tenant_id = "<tenant uuid>";
options.product_id = "<product uuid>";
options.root_keys = &root;
options.root_key_count = 1;
options.data_directory = "<a directory the user can write>";
kleis_client* client = NULL;
if (kleis_client_create(&options, &client) != KLEIS_OK) { /* bad options or storage */ }
kleis_result result;
kleis_client_activate(client, "K1-....", &result); /* once; needs the network */
kleis_entitlement entitlement; /* at the protected operation; no I/O */
kleis_client_check_entitlement(client, "export.pdf", &entitlement);
if (entitlement.granted) { /* do the work */ }
kleis_client_heartbeat(client, &result); /* on your own timer */
kleis_client_destroy(client);Run licensing from your own back end.
Everything the console does for a tenant is an HTTP call: products, plans, entitlements, customers, licenses, activations, usage, policies, credentials, and webhook endpoints. Lists page with one cursor convention, errors are problem documents with stable codes, and a creating request can carry an idempotency key so a retry never issues a second license.
Authorization: Bearer kls_sk_...POST /v1/admin/credentials
Idempotency-Key: 6f1c2d0e-8a57-4b0b-9d0f-2f4f3c1a7e55
{ "name": "billing-sync", "role": "licenseManager" }The API describes itself as an OpenAPI document at /openapi/v1.json on your API host.
Signed, ordered, and retried.
Kleis records an event in the same transaction as the change it describes, so no change goes unreported and no rolled-back change is announced. Deliveries carry an HMAC signature and a timestamp, arrive in order for each endpoint, and are retried with backoff. Payloads carry identifiers and revisions, never a license key.
static bool IsGenuine(byte[] secret, string id, long timestamp, byte[] body, string signature, long now)
{
if (Math.Abs(now - timestamp) > 300) return false;
var prefix = Encoding.UTF8.GetBytes($"{id}.{timestamp}.");
var expected = "v1=" + Convert.ToHexStringLower(HMACSHA256.HashData(secret, [.. prefix, .. body]));
return CryptographicOperations.FixedTimeEquals(Encoding.ASCII.GetBytes(expected), Encoding.ASCII.GetBytes(signature));
}Where each snippet comes from.
Every example on this page is taken from the guides that ship in the repository, under doc/sdk. They are the reference; this page is the tour.
| Example | Guide |
|---|---|
| Install the package | doc/sdk/01-getting-started/01-install-the-packages.md |
| Create a client | doc/sdk/01-getting-started/02-activate-and-check.md |
| Activate once, with the customer's key | doc/sdk/01-getting-started/02-activate-and-check.md |
| Check at the operation, not at the button | doc/sdk/01-getting-started/02-activate-and-check.md |
| Keep the lease current | doc/sdk/01-getting-started/02-activate-and-check.md |
| Register in ASP.NET Core | doc/sdk/01-getting-started/03-aspnet-core.md |
| Protect an endpoint by entitlement | doc/sdk/01-getting-started/03-aspnet-core.md |
| Reserve and report metered usage | doc/sdk/02-concepts/03-metered-usage.md |
| Activate and check from C | doc/sdk/03-reference/04-native-client.md |
| Authenticate | doc/sdk/03-reference/03-administration-api.md |
| Create a credential, idempotently | doc/sdk/03-reference/06-credentials-and-webhook-endpoints.md |
| Verify a webhook delivery | doc/sdk/03-reference/02-webhooks.md |