Skip to content
Kleis
Dark theme
Contact us
Developers

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?

C# SDK

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.

Install the packageshell
dotnet add package Kleis.Client
Create a clientC#
using 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);
Activate once, with the customer's keyC#
var result = await kleis.ActivateAsync(licenseKeyFromUser);
if (!result.Succeeded)
{
    ShowMessage(result.Reason, result.Recovery, result.Message);
}
Check at the operation, not at the buttonC#
public void ExportPdf(Document document)
{
    var decision = kleis.CheckEntitlement("export.pdf");
    if (!decision.Granted)
    {
        throw new LicenseDeniedException(decision.Reason, decision.Recovery);
    }

    // ... export ...
}
Check at the operation, not at the button A disabled button is a courtesy. The check that counts is the one in the code that does the work, because that is the code a patched user interface still has to pass through.
Keep the lease currentC#
await kleis.StartAsync();
kleis.StatusChanged += (_, snapshot) => RefreshUi(snapshot);
Reserve and report metered usageC#
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);
ASP.NET Core

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.

Register in ASP.NET CoreC#
builder.Services
    .AddKleisClient(builder.Configuration.GetSection("Kleis"))
    .AddKleisHostedValidation()
    .AddKleisHealthCheck()
    .AddKleisAuthorization();
Protect an endpoint by entitlementC#
app.MapPost("/reports/advanced", GenerateReport).RequireAuthorization("Kleis:reports.advanced");

[RequireEntitlement("export.pdf")]
public IActionResult Export() { ... }
Native client

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.

Activate and check from CC
#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);
Administration API

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.

AuthenticateHTTP
Authorization: Bearer kls_sk_...
Create a credential, idempotentlyshell
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.

Webhooks

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.

Verify a webhook deliveryC#
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));
}
Guides

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.

ExampleGuide
Install the packagedoc/sdk/01-getting-started/01-install-the-packages.md
Create a clientdoc/sdk/01-getting-started/02-activate-and-check.md
Activate once, with the customer's keydoc/sdk/01-getting-started/02-activate-and-check.md
Check at the operation, not at the buttondoc/sdk/01-getting-started/02-activate-and-check.md
Keep the lease currentdoc/sdk/01-getting-started/02-activate-and-check.md
Register in ASP.NET Coredoc/sdk/01-getting-started/03-aspnet-core.md
Protect an endpoint by entitlementdoc/sdk/01-getting-started/03-aspnet-core.md
Reserve and report metered usagedoc/sdk/02-concepts/03-metered-usage.md
Activate and check from Cdoc/sdk/03-reference/04-native-client.md
Authenticatedoc/sdk/03-reference/03-administration-api.md
Create a credential, idempotentlydoc/sdk/03-reference/06-credentials-and-webhook-endpoints.md
Verify a webhook deliverydoc/sdk/03-reference/02-webhooks.md

Try it against your own build.

Create a workspace, issue a key, and activate the sample application that comes with the SDK.

The connection to the console was lost. Reconnecting…

The connection could not be restored. Nothing you had not saved was sent.

Reload the page