Offline Activation
Offline activation allows your software to validate a license without ever connecting to the internet. The license file is generated externally and delivered to the user, who then loads it into your application.
This is ideal for air-gapped environments, studio machines kept offline, or any user who prefers not to require network access at any point.
Prerequisites
- The KEYZY C++ Client Library integrated into your project — see Quick Start if you haven’t done this yet
- A
ProductDatastructure configured with your credentials
Setup
Create the activator and obtain the validator:
#include "KeyzyLicenseActivator.h"
Keyzy::ProductData productData(
"YOUR_APP_ID",
"YOUR_API_KEY",
"YOUR_PRODUCT_CODE",
"YOUR_CRYPTION_KEY" // Required for offline activation
);
std::unique_ptr<Keyzy::KeyzyLicenseActivator> pActivator =
std::make_unique<Keyzy::KeyzyLicenseActivator>(productData);
std::shared_ptr<Keyzy::KeyzyLicenseValidator> pValidator =
pActivator->getLicenseValidator();
Note: The encryption key (
YOUR_CRYPTION_KEY) is required for offline activation. You can find it on the Products page in the dashboard.
Step 1: Get the Host ID
Each device has a unique Host ID. Your application needs to retrieve this and display it to the user so they can use it to generate a license file:
std::string hostId = pValidator->getHostIdHash();
// Display this to the user — e.g. in a dialog, or copy it to the clipboard
Step 2: Generate the License File
The license file is generated externally using the Host ID from Step 1. There are two ways to do this:
Option A: WooCommerce Plugin
If you are using the KEYZY WooCommerce plugin, your customers can generate the license file directly from your store. The plugin provides a form where the user enters their serial number and Host ID, and downloads the license file.
Option B: Custom Implementation
You can call the Encrypted File API yourself from any language (PHP, C#, Python, JavaScript, etc.). The API returns an encrypted license file. Deliver this file to your user via download, email, or any other method.
Step 3: Activate with the License File
Once the user has the license file on their machine, activate it by passing the file path:
std::string licenseFilePath = "/path/to/license_file.lic"; // provided by the user
Keyzy::LicenseStatus status = pActivator->activateOffline(licenseFilePath);
if (status == Keyzy::LicenseStatus::VALID)
{
// License activated — unlock your application
}
else
{
// Activation failed
}
The library copies and stores the license file on the device. After activation, the original file is no longer needed.
Validate on Subsequent Launches
After activation, validate the license on every launch. Offline validation checks the stored license file locally — no internet required:
Keyzy::LicenseStatus status = pValidator->validateOffline();
if (status == Keyzy::LicenseStatus::VALID)
{
// License is valid — unlock your application
}
else
{
// License is not valid — show the activation form
}
After a successful activation or validation, you can retrieve license details:
std::string licensee = pValidator->getLicenseeName();
std::string email = pValidator->getLicenseeEmail();
std::string sku = pValidator->getSku();
std::string version = pValidator->getVersion();
std::string type = pValidator->getLicenseType();
std::string info = pValidator->getInfo();
For subscription and trial licenses:
std::int64_t startTime = pValidator->getStartTime();
std::int64_t endTime = pValidator->getEndTime();
std::uint64_t daysLeft = pValidator->getDaysLeft();
std::uint64_t daysTotal = pValidator->getDaysTotal();
Offline License Life
You can set an Offline License Life for your SKU in the KEYZY dashboard. This defines how long the license file remains valid (e.g. 90 days). After that period, validateOffline() will no longer return VALID.
You can show the remaining time to your users so they know when renewal is needed:
std::int64_t endTime = pValidator->getEndTime();
// endTime is a Unix timestamp — calculate remaining days from current time
// e.g. "Your license expires in 12 days"
To renew an offline license, the user needs to generate a new license file (repeating Step 2) and activate again. We strongly recommend setting an Offline License Life even for perpetual licenses — it gives you a layer of control over how long a license file stays valid on a device.
Deactivation
Offline deactivation deletes the license file from the device only. It does not contact the KEYZY server — the activation slot on the server is not released:
bool success = pActivator->deactivateOffline();
Note: Since offline deactivation cannot reach the server, the activation count on the KEYZY server is not decremented. If you need to free up the activation slot, you can do this manually from the KEYZY dashboard or via the REST API.
Typical Application Flow
auto pActivator = std::make_unique<Keyzy::KeyzyLicenseActivator>(productData);
auto pValidator = pActivator->getLicenseValidator();
// Try to validate the existing license file
Keyzy::LicenseStatus status = pValidator->validateOffline();
if (status == Keyzy::LicenseStatus::VALID)
{
// License is valid — continue
}
else
{
// No valid license — show the activation form
// 1. Display Host ID: pValidator->getHostIdHash()
// 2. Let the user browse for the license file
std::string filePath = getLicenseFileFromUser(); // your UI code
status = pActivator->activateOffline(filePath);
if (status != Keyzy::LicenseStatus::VALID)
{
// Show error to the user
}
}
Error Handling
All activation and validation methods return a Keyzy::LicenseStatus enum. The most common values for offline activation are INVALID, CANNOT_KEEP_LICENSE_FILE, and SUBSCRIPTION_LICENSE_EXPIRED.
For the complete list of all status codes and their descriptions, see the C++ License Status Codes reference.
Next Steps
- Semi-Online Activation — Activate once online, then validate offline
- Online Activation — Server-validated on every launch
- Trial Licenses — Client-side and server-side trials
- Upgrade Licenses — Transition users between product versions
- C++ License Status Codes — Complete list of all LicenseStatus values
- Quick Start — Getting started from scratch