Add license keys to a C or C++ app

To add license keys to a C++ app, download the prebuilt Licers package, add it with CMake, and call client.validate(key). The library includes its own TLS and Ed25519 code, so there is no OpenSSL or other runtime to ship. There is a plain C99 API and a header-only C++17 wrapper.

Updated by the Licers team

Install with CMake

Download licers-c for your platform from GitHub Releases, unzip it, and point CMake at it.

Setup
# Download licers-c-1.0.1-windows-x64.zip (Windows x64; Linux and macOS coming soon):#   https://github.com/mightycoders00/licers-c/releases/latest# Unzip it into third_party/, then:list(APPEND CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/third_party/licers-c-1.0.1-windows-x64")find_package(licers 1.0 REQUIRED)target_link_libraries(myapp PRIVATE licers::licers)   # or licers::staticlicers_copy_runtime(myapp)                            # Windows: copies licers.dll next to the .exe
  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.

Validate a key

license.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     auto result = client.validate(key);    if (!result.valid()) {        // Expired, revoked, device limit reached... the server says which.        std::cerr << "Not licensed: " << result.error() << "\n";        return 1;    }     std::cout << "Licensed. Expires: " << result.expires_at().value_or("never") << "\n";    return 0;} catch (const licers::Error& e) {    if (e.is_network()) {        // Offline, or the server is down. That is not "unlicensed": try again,        // or allow a few days since the last good check.        std::cerr << "Could not reach the license server. Please try again.\n";    } else {        // A forged or replayed answer, or a key for another of your products.        std::cerr << "License check failed: " << e.what() << "\n";    }    return 1;}

For plugins, games and native tools

  • Audio plugins (VST, AU): never call the network on the audio thread. Check when the editor opens and cache the result.
  • Qt and game engines: calls block for up to the timeout (5 seconds by default), so use a worker thread.
  • Threads: one client can be shared by any number of threads.
  • Static linking is supported through the licers::static target.

Handle every outcome

In C, any status other than LICERS_OK means there is no answer you can trust; licers_last_error() has the message. In C++, the wrapper throws licers::Error.

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 and offline files

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

entitlements.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     auto result = client.validate(key);    if (!result.valid()) {        std::cerr << "Not licensed: " << result.error() << "\n";        return 1;    }     // 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_bool("pro")) std::cout << "Pro features unlocked\n";     auto seats = result.feature_int("seats").value_or(1);    auto tier = result.feature_string("tier").value_or("basic");    std::cout << "Seats: " << seats << " Tier: " << tier << " All: " << result.features_json() << "\n";    return 0;} catch (const licers::Error& e) {    std::cerr << "License error: " << e.what() << "\n";    return 1;}

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.

offline.cpp
#include "licers.hpp"#include <iostream> int main() try {    // 1. Show this to the customer. They send it to you, and you create the file    //    for that device: License keys -> ... -> Offline license file.    std::cout << "Device id: " << licers::hwid() << "\n";     // 2. The customer saves the file next to your app. No network is used here.    auto lic = licers::verify_offline_license("YOUR_PUBLIC_KEY", "license.lic",        "",   // this device        "YOUR_PRODUCT_ID");   // your product     // 3. Use it. It never returns an invalid license: it throws instead.    std::cout << "Licensed to: " << lic.customer().value_or("-")              << " Expires (unix time, 0 = never): " << lic.expires_at() << "\n";    if (lic.feature_bool("pro")) std::cout << "Pro features unlocked\n";    return 0;} catch (const licers::SignatureError&) {    std::cerr << "The license file is missing, damaged or was edited.\n";    return 1;} catch (const licers::Error& e) {    std::cerr << "License file refused: " << e.what() << "\n";    return 1;}

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

usage.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     auto result = client.validate(key);   // first: this activates the device on the key    if (!result.valid()) {        std::cerr << "Not licensed: " << result.error() << "\n";        return 1;    }     auto balance = client.get_usage(key);   // reads only    if (balance.remaining) std::cout << "Left: " << *balance.remaining << "\n";   // empty = no limit     auto usage = client.record_usage(key, 1);   // spend 1 credit, all or nothing    std::cout << "Done. Used so far: " << usage.used << "\n";    return 0;} catch (const licers::UsageExceeded& e) {    std::cout << "Out of credits. Refill: " << e.reported().resets_at << "\n";    return 1;} catch (const licers::Error& e) {    std::cerr << "License error: " << e.what() << "\n";    return 1;}

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

variables.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     auto result = client.validate(key);   // first: this activates the device on the key    if (!result.valid()) {        std::cerr << "Not licensed: " << result.error() << "\n";        return 1;    }     // Values you set on the Remote Variables page. Signed, and only for valid keys.    auto url = client.get_variable(key, "download_url");                   // empty when it isn't set    auto theme = client.get_variable(key, "theme").value_or("dark");       // or your own default    std::cout << url.value_or("-") << " " << theme << "\n";     for (const auto& [name, value] : client.get_variables(key))            // all this key may see        std::cout << name << " = " << value << "\n";    return 0;} catch (const licers::Error& e) {    std::cerr << "License error: " << e.what() << "\n";    return 1;}

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

floating.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     // Takes a seat and keeps it with heartbeats on a background thread. It is freed    // when the variable goes out of scope.    auto seat = client.start_session(key, [](const std::string& reason) {        std::cerr << "Seat lost: " << reason << "\n";   // save the user's work    });    std::cout << "Seat taken: " << seat.seats_used() << " of " << seat.seats_max() << "\n";     // ... your app runs here. Call this at safe points (before a save, between    // jobs). It throws once the seat is gone.    seat.ensure_active();    return 0;} catch (const licers::SeatUnavailable& e) {    std::cerr << "No seat: " << e.what() << "\n";    return 1;} catch (const licers::Error& e) {    std::cerr << "License error: " << e.what() << "\n";    return 1;}

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

updates.cpp
#include "licers.hpp"#include <iostream> int main() try {    licers::Options opts;    opts.product_id = "YOUR_PRODUCT_ID";   // your product: refuses keys for your other products    opts.app_version = "2.4.1";   // shows in Analytics -> App versions    licers::Client client("YOUR_PUBLIC_KEY", opts);   // safe to ship inside your app    const std::string key = "XXXX-XXXX-XXXX-XXXX";   // the customer's license key     auto update = client.check_update(key, "2.4.1", "stable");   // or "beta"     if (update.available) {        std::cout << "New version: " << update.version.value_or("") << "\n";        std::cout << "What's new: " << update.notes.value_or("") << "\n";        // The answer is signed, but download_url and notes are not: check the URL is        // on your own host, and verify the file against a hash you publish.        std::cout << "Download: " << update.download_url.value_or("") << "\n";    } else {        std::cout << "You have the latest version.\n";    }    return 0;} catch (const licers::Error& e) {    std::cerr << "License error: " << e.what() << "\n";    return 1;}

Questions and answers

Which platforms have prebuilt libraries?

See the release page for the current list. You can also build from source with Rust 1.71 or later.

Does it need OpenSSL?

No. TLS and Ed25519 are built in.

Can I call it from other languages?

Yes. The C API uses opaque handles and status codes, so anything that can load a C library can use it.

What does it cost?

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