Start free trial

How to add license keys to your software

A license key system has two halves. A server decides what each key grants and signs that decision; your app checks the signature and acts on it. This guide goes through both with Carcha Seal, from choosing what a key grants to testing a revoked key before release, with code for Electron and Node.js, C# and C++.

Reading time
6 min
Updated
11 November 2026
Sections
8
On this page
1. Decide what a key grants2. Create a product and a policy3. Issue keys when you sell4. Activate once, check at every start5. Act on the state and gate features6. Offline computers and new computersFloating licenses: take a seat instead7. Test the unhappy paths before release

1. Decide what a key grants

Before any code, write down what a customer gets for their money: forever or until a date, on how many computers, with which features, and whether updates stop at some point. Those answers become a policy. If you are unsure which model fits, software license types compares perpetual, subscription, trial, node-locked and floating licenses.

Do not generate keys inside the app. A key that the app can generate, someone else can generate by reading the app. The key only identifies the license; what it grants lives on the server and reaches the app as a signed lease.

2. Create a product and a policy

Sign up, create a product with a code your app will send (for example example-studio), and set its default policy in the console. The same can be done with the admin API. A perpetual license for three computers with a year of updates:

POST /api/policies
{
  "productId": "<your product id>",
  "code": "pro-perpetual",
  "name": "Pro, perpetual, 3 computers",
  "maxActivations": 3,
  "durationDays": null,
  "maintenanceDays": 365,
  "features": ["pro"]
}

The policy also sets how often the app checks in and how long it keeps working without the server: by default every 72 hours, with 7 more days of grace.

3. Issue keys when you sell

  • By hand: issue a license in the console and send the key, or let the console email it to the customer.
  • From your store: connect a Lemon Squeezy store, and each purchase creates a license and emails the key. Renewals, cancellations and refunds update it.
  • From your own backend: call the admin API with an API key.
POST /api/licenses
Authorization: Bearer <API key>
{
  "productId": "<your product id>",
  "policyId": "<the pro-perpetual policy id>",
  "customerName": "Example GmbH",
  "customerEmail": "it@example.com",
  "reference1": "order-10442"
}

The response holds the key once. Carcha Seal keeps no copy of it, so a lost key is replaced, not looked up.

4. Activate once, check at every start

The app needs your server address, the product code and your public signing keys (the current and the next, so the server can rotate its key without an app update). The console's Integrate page shows them all. Then the pattern is the same in every SDK: check at start, which works offline from the saved lease, and activate only when there is no license yet.

Electron and Node.js

npm install @carchalabs/seal-electron
const { Seal } = require('@carchalabs/seal-electron');

const seal = new Seal({
  serverUrl: 'https://licenses.example.com',
  product: 'example-studio',
  publicKey: [currentKeyPem, nextKeyPem],
  storageDir: app.getPath('userData'),
  appVersion: app.getVersion(),
});

let state = await seal.check();                 // at every start; offline from the saved lease
if (state.status === 'unlicensed') state = await seal.activate(keyTheUserTyped);

In Electron, also pass a secureStore built on safeStorage; the Electron guide has the full main-process code.

C# and .NET

dotnet add package CarchaLabs.Seal
using CarchaLabs.Seal;

using var client = new SealClient(new SealOptions
{
    Product = "example-studio",
    ServerUrl = "https://licenses.example.com",
    PublicKeys = PublicKeys,             // the current and next key, in your code
    StorageDirectory = appDataDir,       // license.dat is kept here
    AppVersion = "2.4.0",
});

LicenseState state = await client.CheckAsync();
if (state.Status == LicenseStatus.Unlicensed) state = await client.ActivateAsync(keyTheUserTyped);

C++

find_package(CarchaSeal 0.4 REQUIRED)
target_link_libraries(my_app PRIVATE CarchaSeal::seal)
carcha_seal_copy_runtime(my_app)
#include <carcha/seal.hpp>
namespace seal = carcha::seal;

seal::Options options;
options.product = "example-studio";
options.server_url = "https://licenses.example.com";
options.public_keys = kPublicKeys;
options.storage_dir = app_data_dir;
options.app_version = "2.4.0";

seal::Client client(options);
seal::State state = client.check();
if (state.status == seal::Status::Unlicensed) state = client.activate(key_the_user_typed);

Activating ties the license to this computer and stores a lease signed with Ed25519. Activating again on the same computer reuses its seat. Run check() again every few hours while the app is open, so a renewal, a new feature or a suspension arrives without a restart.

5. Act on the state and gate features

The state says what to do. valid and grace run the app; in grace, tell the user to go online before it ends. Anything else (expired, suspended, revoked, a lease for another computer) locks the paid parts and shows the message the state carries. Features are asked by name:

if (Seal.hasFeature(state, 'pro')) enableProTools();          // Electron and Node.js
if (state.HasFeature("pro")) EnableProTools();                // C#
if (state.has_feature("pro")) enable_pro_tools();             // C++

A check in your code can be patched out. Code or data you encrypt for a feature can only be opened on a computer whose lease includes that feature; see encrypting data and code for a feature.

6. Offline computers and new computers

  • Temporarily offline: nothing to do. The app runs from its lease until the check-in deadline plus grace.
  • Never online: the app writes a request file (offlineRequest), the customer uploads it on your server's offline page from any connected device, and the license file that comes back works on that computer only (activateOffline). Allow it per policy with offline days.
  • A new computer: deactivate() on the old one frees the seat. A user can move a seat three times in 12 months; you can free one from the console at any time.

Floating licenses: take a seat instead

If the policy is floating, the app takes a seat while it runs instead of activating a computer. The seat renews itself and is given back on quit; there is no offline grace, so the app needs the server while it runs.

const seat = await seal.checkout(keyTheUserTyped);   // seats_exhausted when every seat is in use
seat.on('lost', (loss) => lockPaidFeatures(loss));    // the server could not be reached in time, or the seat was freed

The C++ and .NET SDKs take seats the same way. Seats can be counted per computer, running copy, user, or user per computer; see concepts.

7. Test the unhappy paths before release

  • Run npx @carchalabs/seal-quickstart or use a test key from the sandbox to see a working lease before writing code.
  • Disconnect the network and start the app: it should run from the lease, then move to grace, then lock.
  • Suspend and revoke the test license in the console, then check in: the app should lock and show the message.
  • Activate on more computers than the policy allows: the extra one should be refused with the seat limit.
  • Turn the clock back more than a day: the SDK reports clock_suspect.

How the lease is verified · Documentation · Try the live demo

Sources

Each page was checked on 11 November 2026. The code is the published SDKs' API, as in the documentation.

License your app in an afternoon.

14-day trial, no card. Your own server address and signing key from the first minute.