Add license keys to a C# or .NET app

To add license keys to a C# app, run dotnet add package Licers, create a LicenseClient with your public key, and await ValidateAsync(key). The library checks the server’s Ed25519 signature in managed code with no other dependencies, and works on .NET Framework 4.6.1 and later, .NET Core, .NET 5+, Mono and Unity.

Updated by the Licers team

Set it up

  1. Create a free account and add a product.
  2. Copy your public key and product id from the Integration page. The public key is safe to ship inside your app.
  3. Issue a key: set how many devices it may use, when it expires, and any entitlements.
  4. Add the code below. On the first check the device is bound to the key; past the device limit a new machine is refused.
Terminal
dotnet add package Licers
LicenseCheck.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key ValidationResult result;try{    result = await client.ValidateAsync(key);}catch (NetworkException){    // Offline, or the server is down. That is not "unlicensed": try again, or    // allow a few days since the last good check.    Console.Error.WriteLine("Could not reach the license server. Please try again.");    return;}catch (LicenseException e){    // A forged or replayed answer, or a key for another of your products.    Console.Error.WriteLine("License check failed: " + e.Message);    return;} if (!result.Valid){    // Expired, revoked, device limit reached... the server says which.    Console.Error.WriteLine("Not licensed: " + result.Error);    return;} Console.WriteLine("Licensed. Expires: " + (result.ExpiresAt ?? "never"));

Works with WinForms, WPF, Avalonia and console apps

The package targets .NET Standard 2.0 and includes its own Ed25519 (RFC 8032) and JSON code, so there are no version conflicts and nothing extra to ship. Calls are async: await them while a splash screen is shown instead of blocking the UI thread.

Handle every outcome

ValidateAsync returns Valid = false with Error when the key is refused. It throws SignatureException for a forged answer, and NetworkException or ServerException when the server cannot be reached.

What happenedWhat your app should do
The key is expired, revoked, blocked or over its device limitShow the message the server sent. You can reword every one of them on the Custom Messages page.
The answer has a bad signature or an old nonceRefuse. Somebody is faking the server.
The server cannot be reached, or returns a 5xx errorRetry, or allow a grace period since the last good check. Being offline is not the same as being unlicensed.

Seats, credits, updates and offline files

Entitlements. Switch features on per key: true/false, numbers or text. They come from the signed answer.

Entitlements.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key var result = await client.ValidateAsync(key);if (!result.Valid){    Console.Error.WriteLine("Not licensed: " + result.Error);    return;} // Entitlements of this key, for example {"pro": true, "seats": 5, "tier": "gold"}.// They are read from the signed copy, so nobody can edit them on the way.if (result.Feature("pro") is true) Console.WriteLine("Pro features unlocked"); var seats = result.Feature("seats") is long n ? n : 1;      // whole numbers are longvar tier = result.Feature("tier") as string ?? "basic";Console.WriteLine($"Seats: {seats} Tier: {tier} Entitlements: {result.Features.Count}");

Offline file. Check a signed .lic file with no internet at all, for air-gapped machines. Signature, product, expiry, device and operating system are all checked on the computer.

OfflineCheck.cs
using System;using System.Collections.Generic;using Licers; // 1. Show this to the customer. They send it to you, and you create the file//    for that device: License keys -> ... -> Offline license file.Console.WriteLine("Device id: " + Hwid.Get()); // 2. The customer saves the file next to your app. No network is used here.IReadOnlyDictionary<string, object> lic;try{    lic = OfflineLicense.Verify("YOUR_PUBLIC_KEY", "license.lic",        expectedProductId: "YOUR_PRODUCT_ID");   // your product}catch (SignatureException){    Console.Error.WriteLine("The license file is missing, damaged or was edited.");    return;}catch (InvalidLicenseException e){    Console.Error.WriteLine("License file refused: " + e.Message);   // expired, other device, OS or product    return;} // 3. Use it. It never returns an invalid license: it throws instead.Console.WriteLine("Licensed to: " + lic["customer"] + " Expires (unix time): " + (lic["expires_at"] ?? "never"));if (lic["features"] is Dictionary<string, object> features && features.TryGetValue("pro", out var pro) && pro is true)    Console.WriteLine("Pro features unlocked");

Usage credits. Meter what the customer does: “100 exports”, “5,000 AI calls a month”. Spending is all or nothing.

UsageCredits.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key var result = await client.ValidateAsync(key);   // first: this activates the device on the keyif (!result.Valid){    Console.Error.WriteLine("Not licensed: " + result.Error);    return;} Console.WriteLine("Left: " + (await client.GetUsageAsync(key)).Remaining);   // reads only; null = no limit try{    var usage = await client.RecordUsageAsync(key, 1);   // spend 1 credit, all or nothing    Console.WriteLine($"Done. {usage.Remaining} credits left");}catch (UsageExceededException e){    e.Usage.TryGetValue("resets_at", out var refill);    Console.WriteLine("Out of credits. Refill: " + (refill ?? "buy more"));}

Remote variables. Values you change in the dashboard without shipping an update: a link, a message, a switch.

RemoteVariables.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key var result = await client.ValidateAsync(key);   // first: this activates the device on the keyif (!result.Valid){    Console.Error.WriteLine("Not licensed: " + result.Error);    return;} // Values you set on the Remote Variables page. Signed, and only for valid keys.var url = await client.GetVariableAsync(key, "download_url");      // null when it isn't setvar theme = await client.GetVariableAsync(key, "theme", "dark");   // or your own defaultvar everything = await client.GetVariablesAsync(key);              // all this key may see Console.WriteLine($"{url} {theme} {everything.Count} variables");

Floating seats. Let only N people run the app at the same time, on any computers.

FloatingSeat.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key try{    // Takes a seat, keeps it with heartbeats in the background, and frees it    // when the block ends.    using (var seat = await client.StartSessionAsync(key, onLost: reason => Console.Error.WriteLine("Seat lost: " + reason)))    {        Console.WriteLine($"Seat taken: {seat.SeatsUsed} of {seat.SeatsMax}");         // ... your app runs here. Call this at safe points (before a save,        // between jobs). It throws once the seat is gone.        seat.EnsureActive();    }}catch (SeatUnavailableException e){    Console.Error.WriteLine("No seat: " + e.Message);}

Updates. Tell the customer about a new version. Only a valid, active key is given the download link.

UpdateCheck.cs
using System;using Licers; var client = new LicenseClient("YOUR_PUBLIC_KEY", new ClientOptions   // safe to ship inside your app{    ProductId = "YOUR_PRODUCT_ID",   // your product: refuses keys for your other products    AppVersion = "2.4.1",   // shows in Analytics -> App versions});var key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key var update = await client.CheckUpdateAsync(key, "2.4.1", "stable");   // or "beta" if (update.UpdateAvailable){    Console.WriteLine("New version: " + update.Version);    Console.WriteLine("What's new: " + update.Notes);    // The answer is signed, but DownloadUrl and Notes are not: check the URL is    // on your own host, and verify the file against a hash you publish.    Console.WriteLine("Download: " + update.DownloadUrl);}else{    Console.WriteLine("You have the latest version.");}

Questions and answers

Can someone decompile my C# app and remove the check?

C# is easy to decompile, so a determined person can patch your build. Signed answers stop fake servers and key generators; add an obfuscator and keep valuable logic on a server for more.

Does it support .NET Framework?

Yes, 4.6.1 and later.

How is the computer identified?

The device id is a SHA-256 hash of the operating system’s machine id (Windows MachineGuid, Linux /etc/machine-id, macOS IOPlatformUUID). It survives reinstalls of your app, and the Node, .NET, Kotlin, Java, Rust, Go, C and C++ SDKs compute the same value on the same machine.

What does it cost?

Nothing today. Every feature is free and unlimited: products, keys, devices, validations, offline files and floating seats. See pricing.