Licers 1.3.1
dotnet add package Licers --version 1.3.1
NuGet\Install-Package Licers -Version 1.3.1
<PackageReference Include="Licers" Version="1.3.1" />
<PackageVersion Include="Licers" Version="1.3.1" />
<PackageReference Include="Licers" />
paket add Licers --version 1.3.1
#r "nuget: Licers, 1.3.1"
#:package Licers@1.3.1
#addin nuget:?package=Licers&version=1.3.1
#tool nuget:?package=Licers&version=1.3.1
Licers for .NET and Unity
License-key verification for C# / .NET and Unity apps, against Licers.
Every answer from the license server is Ed25519-signed with your account key and checked here, with a fresh random nonce per call — so a cracked "fake license server", an edited response or a replayed one is refused.
- No dependencies. Targets .NET Standard 2.0: .NET Framework 4.6.1+, .NET Core / .NET 5+, Mono, Xamarin and Unity 2018.1+. Ed25519 verification (RFC 8032) and JSON are built in, so nothing else needs to be in your Unity project.
dotnet add package Licers
Your public key and product id are on the dashboard’s Integration page. The public key is safe to ship inside your app. Each example below is a complete file.
Check a key
Run this when your app starts. The first check binds the device to the key; past the key’s device limit a new device is refused.
In the dashboard: create a product, then a license key for it.
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"));
- A refused key is a normal answer with a message. An unreachable server is an error: never treat it as “unlicensed”.
ValidateAsync returns Valid = false with Error when the server refuses the key. It throws for a forged answer or an unreachable server, so being offline is never mistaken for being unlicensed.
Entitlements
Switch features on per key: true/false, numbers or text. They come from the signed answer.
In the dashboard: set Entitlements (JSON) on the key or on its plan, for example {"pro": true, "seats": 5}.
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 long
var tier = result.Feature("tier") as string ?? "basic";
Console.WriteLine($"Seats: {seats} Tier: {tier} Entitlements: {result.Features.Count}");
- Compare with true exactly. The text "false" is not the same as false.
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.
- Your app shows its device id, and the customer sends it to you.
- License keys → ⋯ → Offline license file: paste the device id, set how many days it lasts, download the .lic file.
- Send it to the customer. Your app reads it from disk.
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");
- Revoking a key can’t reach a file you already sent, so give files a short life.
- The expiry uses the computer’s own clock.
- A blank device id makes a file that works on any computer.
Sign in with email
Instead of a key: SignInAsync() shows a code, opens the customer portal in the
browser and waits while the customer signs in with the email on their license
and approves this computer. The token works wherever a key does, only on this
device. Turn on "Sign in with email" for the product on the Products page first.
var token = await client.SignInAsync(s => Console.WriteLine($"Open {s.Url} and enter {s.Code}"));
// keep the token, then use it instead of the key:
var result = await client.ValidateAsync(token);
if (result.SignedOut) { /* signed out in the portal or dashboard: forget it, sign in again */ }
await client.SignOutAsync(token); // your app's "Sign out"
Calls that throw do so with SignedOutException when the sign-in has ended.
Waiting can end with SignInDeniedException or SignInExpiredException.
StartSignInAsync() gives you the code and URL for your own window;
await s.WaitAsync() collects the token.
License server (no internet)
For networks without internet, the customer runs the free Licers License Server
(https://licers.com/docs#license-server). Point the client at it with
new ClientOptions { ApiUrl = "http://licensing-pc:8090", ProductId = "...", LocalServer = true },
then StartSessionAsync("") or ValidateAsync("") (the key can be empty). The
SDK checks the server's file with your public key; entitlements, end date and
seat limit come from that file, and no seat lasts beyond the file. License-server
mode must be on: only then are the server's answers trusted, and only for
validating and seats. Usage credits, remote variables and update checks always
come from Licers itself.
Usage credits
Meter what the customer does: “100 exports”, “5,000 AI calls a month”. Spending is all or nothing.
In the dashboard: give the key a credit limit, and a daily or monthly refill if you want one.
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 key
if (!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"));
}
- Check the key on this device first.
- After a network error the credits may already be spent: read the balance before trying again.
Remote variables
Values you change in the dashboard without shipping an update: a link, a message, a switch.
In the dashboard: add them on the Remote Variables page.
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 key
if (!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 set
var theme = await client.GetVariableAsync(key, "theme", "dark"); // or your own default
var everything = await client.GetVariablesAsync(key); // all this key may see
Console.WriteLine($"{url} {theme} {everything.Count} variables");
- Check the key on this device first.
- Values are text. A product’s value wins over one for all products.
Floating seats
Let only N people run the app at the same time, on any computers.
In the dashboard: set Max concurrent sessions on the key.
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);
}
- If the server can’t be reached, the seat is kept until its last signed expiry and then given up.
- A crashed app frees its seat by itself after the session timeout.
Updates
Tell the customer about a new version. Only a valid, active key is given the download link.
In the dashboard: add the version and its download link on the Releases page.
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.");
}
- The answer is signed, including “no update”. The download link is not: check its host and the file’s hash.
Unity
- Add the package with NuGetForUnity, or copy
Licers.dll(from the NuGet package'slib/netstandard2.0) intoAssets/Plugins. - Use .NET Standard 2.1 / .NET Framework API compatibility (Project Settings → Player).
- Pass Unity's device id, which works on every platform including mobile:
var result = await client.ValidateAsync(key, hwid: SystemInfo.deviceUniqueIdentifier);
The calls are async; await them from an async void Start() or a coroutine wrapper. WebGL can't make arbitrary HTTP requests from HttpClient, so license checks there need a server of your own.
Exceptions
| Exception | Meaning |
|---|---|
InvalidLicenseException |
The server refused the key |
ProductMismatchException |
Correctly signed, but for a different product |
UsageExceededException |
Not enough credits; nothing was spent |
SignatureException |
Signature or nonce check failed — forged or replayed |
NetworkException |
Server unreachable |
ServerException |
Server answered 5xx — an outage, not a verdict (a NetworkException) |
ProtocolException |
Not a usable reply (redirects are never followed) |
SeatUnavailableException |
No free floating seat, or a held seat was lost |
All derive from LicenseException.
Device id
Hwid.Get() is SHA-256 of "licers:" + the OS machine id (Windows MachineGuid, Linux /etc/machine-id, macOS IOPlatformUUID) — the same value the Node and Rust SDKs produce on that machine. Where none is readable, a random id is stored once under LocalApplicationData (LICERS_HWID_DIR overrides).
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.