General overview of Keyzy C++ Client Library
The main idea behind the Keyzy C++ Client library is to offer simple methods for activating and validating your product's license management. Additionally, it provides functionality for registering trial licenses.
To activate and validate licenses, you need to utilize the following classes:
- KeyzyLicenseActivator
- KeyzyLicenseValidator
These classes provide the necessary functionality for license activation and validation within the Keyzy C++ Client library.
To deposit licenses from directly client-side, you will need to utilize the LicenseDepositHandler class. This class enables the depositing of licenses from the KEYZY service to the client device.
The KeyzyLicenseActivator class utilizes the ProductData structure as an input argument in its constructor. This allows the system to identify the specific product on the server side for license activation and validation purposes. By providing the relevant product information through the ProductData structure, the system can accurately handle the licensing operations associated with that product.
struct ProductData
{
ProductData() : _useHostIdInOffilneActivation(true) {}
ProductData(std::string appId, std::string apiKey, std::string productCode,
std::string cryptionKey, bool useHostIdInOfflineActivation = true)
: _appId(appId)
, _apiKey(apiKey)
, _productCode(productCode)
, _cryptionKey(cryptionKey)
, _useHostIdInOffilneActivation(useHostIdInOfflineActivation) {}
std::string _appId;
std::string _apiKey;
std::string _productCode;
std::string _cryptionKey; /** Offline activation schema only */
bool _useHostIdInOffilneActivation; /** Default set to "true" */
};
- You can obtain an appId and apiKey pair from the "App Keys" section of the Keyzy Admin Panel at App Keys .
- The product code can be obtained from the "Products" section of the Keyzy Admin Panel at Products .
- If you are using the offline activation/validation schema, you will need to set the _cryptionKey member. You can retrieve this key from the "Products" section of the Keyzy Admin Panel at Products as well.
Product activation process
The product activation process should be performed only once for each run of the software, usually when users launch your application for the first time. The Keyzy C++ Client Library will internally store the provided data and use it for license validation purposes.
KeyzyLicenseActivator class provides the following methods that should be uses to activate or deactivate a license:
- LicenseStatus activateOnline(const std::string& serialNumber);
- LicenseStatus deactivateOnline();
- LicenseStatus activateSemiOnline(const std::string& serialNumber);
- LicenseStatus activateSemiOnline();
- LicenseStatus deactivateSemiOnline();
- LicenseStatus activateOffline(const std::string& licenseFilePath);
- bool deactivateOffline();
License validation process
Online license validation
The online validation process uses a serial number, which can be provided by the user or obtained through the LicenseDepositHandler along with other information such as ProductData or HostId. The information is used to send an HTTP POST request to the KEYZY Service to validate the license.
You need to call the LicenseStatus validateOnline() function from the KeyzyLicenseValidator class. If the serial number is valid, this function will return the value LicenseStatus::VALID.
Offline license validation
The offline validation process uses a license file provided by the KeyzyLicenseActivator class and does not require an internet connection.
You need to call the LicenseStatus validateOffline() function from KeyzyLicenseValidator class. If the license file is valid, this function will return the value LicenseStatus::VALID.
Semi-Online activation schema uses the offline validation process as well.
Dealer information
After a successful validateOnline() or validateOffline(), the dealer name is available from KeyzyLicenseValidator for dealer-distributed licenses: getDealerName() returns the dealer's display name (empty string when the license has no dealer). It is populated by the online and offline flows alike.
All error statuses
Network-layer statuses. CONNECTION_ERROR and the NETWORK_* statuses below are returned by any method that performs a network request — validateOnline(), activateOnline(), activateSemiOnline(), downloadLicenseFile(), upgradeLicense(), deactivateOnline(), registerTrialLicense(), registerOfflineDistributedLicense() — when the call fails at the network layer (no HTTP response received). They let your application show the end user a specific, actionable message instead of a generic "connection problem."
| Status | Explanation |
| LicenseStatus::EXPIRED | A locally-stored trial has expired. Returned by validateTrialLicense() from KeyzyLicenseValidator. (Client-side) |
| LicenseStatus::NOT_AUTHORIZED | The appId / apiKey pair is wrong or not authorized. Returned by validateOnline() from KeyzyLicenseValidator. (Server-side) |
| LicenseStatus::SERIAL_INVALID | The serial number is invalid or not registered. Returned by validateOnline() (KeyzyLicenseValidator) and downloadLicenseFile() (KeyzyLicenseManager). (Server-side) |
| LicenseStatus::PRODUCT_NOT_EXIST | The product code does not exist. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::PRODUCT_NOT_EXIST_FOR_USER | The product code does not exist. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::PRODUCT_NOT_ACTIVE | The product exists but is not active. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::SKU_NOT_EXIST | The SKU does not exist. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::SKU_NOT_ACTIVE | The SKU exists but is not active. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::REACHED_MAX_NUMBER_OF_HOST | The license has reached its maximum number of activated devices (hosts). Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::PRODUCT_NOT_EXIST_FOR_SKU | The product exists but is not part of the SKU linked to this license. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::ACTIVATION_DEACTIVATED | This device's activation was deactivated (revoked) on the server. Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::SUBSCRIPTION_LICENSE_EXPIRED | The subscription license has expired (its end date has passed). Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::SUBSCRIPTION_LICENSE_NOT_STARTED | The subscription license has not started yet (future start date). Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::TRIAL_LICENSE_EXPIRED | The server-side trial license has expired. (Distinct from EXPIRED, which is a local trial check.) Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::TRIAL_LICENSE_NOT_STARTED | The server-side trial license has not started yet (future start date). Returned by validateOnline() and downloadLicenseFile(). (Server-side) |
| LicenseStatus::CANNOT_KEEP_SERIAL | The SDK could not save the serial number to the device (write failed). Happens locally, before any server contact. (Client-side) |
| LicenseStatus::CANNOT_KEEP_LICENSE_FILE | The SDK could not save the license file to the device (write failed — often a wrong or unwritable target path). Happens locally. (Client-side) |
| LicenseStatus::ACTIVATION_DELETED | The activation was successfully removed from the KEYZY servers. A success status, returned by the deactivation flow. (Server-side) |
| LicenseStatus::CLIENT_SERIAL_DOES_NOT_EXIST | No serial number is stored on the device. (Client-side) |
| LicenseStatus::CONNECTION_ERROR | Network or firewall error (umbrella). Returned when the connection fails at the network layer and no more specific NETWORK_* status applies. |
| LicenseStatus::NETWORK_DNS_FAILED | DNS resolution failed (DoH and OS resolver both failed). Likely no internet, or DNS blocked. Ask the user to check their internet connection. |
| LicenseStatus::NETWORK_REFUSED | TCP connection refused — typically a firewall blocking outbound HTTPS. Ask the user to check their firewall settings. |
| LicenseStatus::NETWORK_TIMEOUT | Connection timed out. With no HTTP 407, this is usually a firewall blocking outbound HTTPS or a proxy silently dropping the connection. Ask the user to check firewall/proxy settings. |
| LicenseStatus::NETWORK_TLS_FAILED | TLS handshake failed — corporate SSL inspection, MITM, or a wrong system clock. Ask the user to check the system date/time and any security software. |
| LicenseStatus::NETWORK_PROXY_REQUIRED | HTTP 407: the network requires an authenticated proxy. Ask the user to contact their IT department to whitelist api.keyzy.io, or to configure proxy credentials at the OS level. |
| LicenseStatus::NETWORK_HOSTS_TAMPERED | The OS resolver returned a private/loopback IP for api.keyzy.io — a strong sign of hosts-file / DNS manipulation. Advise the user to check their hosts file. |
| LicenseStatus::TOO_MANY_REQUESTS | The client sent too many requests in a short time and was rate-limited (HTTP 429). (Server-side) |
| LicenseStatus::NO_ACTIVE_SUBSCRIPTION | The account holder has a subscription problem on the KEYZY side (i.e. your own KEYZY plan is inactive — not the end user's license). (Server-side) |
| LicenseStatus::CURRENT_LICENSE_DOES_NOT_EXIST | During an upgrade, the source (current) license serial does not exist on the KEYZY servers. (Server-side) |
| LicenseStatus::UPGRADE_LICENSE_DOES_NOT_EXIST | During an upgrade, the target (upgrade) license serial does not exist on the KEYZY servers. (Server-side) |
| LicenseStatus::UPGRADE_LICENSE_DOES_NOT_MATCH | The target license is not a valid upgrade path for the current license. (Server-side) |
| LicenseStatus::ANOTHER_TRIAL_LICENSE_ALREADY_ACTIVATED | A trial has already been activated on this device; a second trial is blocked. (Server-side) |
| LicenseStatus::SKU_NUMBER_VALIDATION | The sku_number parameter failed validation (HTTP 422). (Server-side) |
| LicenseStatus::PRODUCT_CODE_VALIDATION | The product_code parameter failed validation (HTTP 422). (Server-side) |
| LicenseStatus::NAME_VALIDATION | The name parameter failed validation (HTTP 422). (Server-side) |
| LicenseStatus::EMAIL_VALIDATION | The email parameter failed validation. Rejected server-side (HTTP 422) or client-side (empty email in register* calls). (Server-side & Client-side) |
| LicenseStatus::SERIAL_VALIDATION | The serial parameter failed validation (HTTP 422 on register). (Server-side) |
| LicenseStatus::CODE_VALIDATION | The code parameter failed validation (HTTP 422 on register-trial). (Server-side) |
| LicenseStatus::NO_FREE_LICENSES | No unassigned (free) licenses remain in this SKU's pool to register. Returned by registration flows (including trial registration) when the pool is exhausted — generate more licenses for the SKU. (Server-side) |
| LicenseStatus::NAME_OR_EMAIL_VALIDATION | Deprecated since the 2026-04-20 server hardening — never produced by the current server. Kept for ABI compatibility. |
| LicenseStatus::LICENSE_NOT_EXIST_NOT_ASSIGNED_DEALER_ALREADY_DEPOSITED | Register-offline-distributed-license flow: the license does not exist, is not assigned to a dealer, or has already been deposited. (Server-side) |
| LicenseStatus::INVALID | The license is invalid or could not be verified — generic failure when no more specific status applies. |
Example of register offline distributed license process
Demonstrates depositing an offline license by the client side. It updated the name and the email address of an offline license.
#include <KeyzyLicenseActivator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
int main()
{
ProductData data;
const std::string serialNumber = "****-****-****-****-****";
data._appId = "********";
data._apiKey = "****************************************";
data._productCode = "********-****-****-****-************";
data._cryptionKey = "********************************";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler = pLicenseActivator->getLicenseDepositHandler();
LicenseStatus registerDistributedLicenseStatus = LicenseStatus::VALID;
registerDistributedLicenseStatus = pLicenseDepositHandler->registerOfflineDistributedLicense(serialNumber, "John Doe", "john@doe.com");
if (registerDistributedLicenseStatus != LicenseStatus::VALID) {
std::cout << errorStatuses(registerDistributedLicenseStatus) << std::endl;
} else {
std::cout << "The license successfully registered.";
}
return 0;
}
// please find errorStatuses() function below of this page
Example of register trial license process
Demonstrates depositing a trial license from the client side. Sends a trial license request with the provided SKU number to the KEYZY service. If a free trial license is available for the given SKU number, KEYZY deposits the license and responds with the information.
#include <KeyzyLicenseActivator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
int main()
{
ProductData data;
std::string serialNumber = "";
data._appId = "********";
data._apiKey = "****************************************";
data._productCode = "********-****-****-****-************";
data._cryptionKey = "********************************";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler = pLicenseActivator->getLicenseDepositHandler();
LicenseStatus registerTrialStatus = LicenseStatus::VALID;
LicenseInfo licenseInfo;
registerTrialStatus = pLicenseDepositHandler->registerTrial(licenseInfo, "your-sku-number", "optional-licensee-name");
if (registerTrialStatus != LicenseStatus::VALID) {
std::cout << errorStatuses(registerTrialStatus) << std::endl;
} else {
std::cout << "Start Time : " << licenseInfo._startTime << std::endl;
std::cout << "End Time : " << licenseInfo._endTime << std::endl;
std::cout << "Serial Number : " << licenseInfo._serialNumber << std::endl;
serialNumber = licenseInfo._serialNumber;
}
return 0;
}
// please find errorStatuses() function below of this page
Example of upgrade license process
The upgradeLicense() method only performs the upgrade on the KEYZY server. It does not activate or validate the new license, and does not store the target serial on the device. To activate the target serial afterward, use one of the activation methods (e.g. activateOnline, activateSemiOnline).
Upgrade using stored serial (recommended)
If the source serial is already stored on the device (from a previous activation), you only need to provide the target serial:
#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
// Source serial is read from the device automatically
LicenseStatus status = pLicenseActivator->upgradeLicense("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Upgrade License Status: " << errorStatuses(status) << std::endl;
if (status == LicenseStatus::VALID) {
// Activate the target serial on the device
status = pLicenseActivator->activateOnline("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Activation Status: " << errorStatuses(status) << std::endl;
}
}
// please find errorStatuses() function below of this page
Upgrade with explicit source and target serials
You can also provide both serials explicitly:
#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
LicenseStatus status = pLicenseActivator->upgradeLicense("SOUR-CESE-RIAL-XXXX-XXXX", "TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Upgrade License Status: " << errorStatuses(status) << std::endl;
if (status == LicenseStatus::VALID) {
// Activate the target serial on the device
status = pLicenseActivator->activateOnline("TARG-ETSE-RIAL-XXXX-XXXX");
std::cout << "Activation Status: " << errorStatuses(status) << std::endl;
}
}
// please find errorStatuses() function below of this page
Example of depositing a trial license using the LicenseDepositHandle class
#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a deposit handler object
std::shared_ptr<LicenseDepositHandler> pLicenseDepositHandler =
pLicenseActivator->getLicenseDepositHandler();
// Get a status enum object
LicenseStatus registerTrialStatus = LicenseStatus::VALID;
// Get a license info object
LicenseInfo licenseInfo;
// Perform the registration process
registerTrialStatus = pLicenseDepositHandler->registerTrial(licenseInfo, "your-sku-number", "optional-licensee-name", "optional-licensee-email");
// Check the result
if (registerTrialStatus != LicenseStatus::VALID) {
// Error
std::cout << errorStatuses(registerTrialStatus) << std::endl;
} else {
std::cout << "Start Time : " << licenseInfo._startTime << std::endl;
std::cout << "End Time : " << licenseInfo._endTime << std::endl;
std::cout << "Serial Number : " << licenseInfo._serialNumber << std::endl;
// Get the serial number to use in one of the activation process
serialNumber = licenseInfo._serialNumber;
}
}
// please find errorStatuses() function below of this page
Example of online license validation and activation process
#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a validator object
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator =
pLicenseActivator->getLicenseValidator();
const std::string serialNumber = "XXXX-XXXX-XXXX-XXXX-XXXX";
LicenseStatus status = LicenseStatus::VALID;
if (pLicenseValidator->validateOnline() != LicenseStatus::VALID) {
// bring serial number input window to the user
status = pLicenseActivator->activateOnline(serialNumber);
std::cout << std::endl;
std::cout << "Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
} else {
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
std::cout << "Online Validation Status: " << errorStatuses(status) << std::endl << std::endl;
}
status = pLicenseActivator->deactivateOnline();
std::cout << "Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
}
// please find errorStatuses() function below of this page
Example of offline license validation and activation process
#include <iostream> // for std::cout
#include <KeyzyLicenseActivator.h>
#include <KeyzyLicenseValidator.h>
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
// fill ProductData struct to identify specific product
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Get an activator object
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator =
std::make_unique<KeyzyLicenseActivator>(data);
// Get a validator object
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator =
pLicenseActivator->getLicenseValidator();
LicenseStatus status = LicenseStatus::VALID;
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateOffline("/Users/user111/Downloads/license_file.lic");
std::cout << "Offline Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
} else {
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
}
// This won't deactivate the license in KEYZY servers. Only delete the license file locally.
bool res = pLicenseActivator->deactivateOffline();
if (!res)
status = LicenseStatus::INVALID;
else
status = LicenseStatus::ACTIVATION_DELETED;
std::cout << "Offline Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
}
// please find errorStatuses() function below of this page
Full example (Online Activation, Semi-Online Activation, Offline Activation, Trial Due Date Activation)
#include <KeyzyLicenseActivator.h>
#include <KeyzyLicenseValidator.h>
#include <iostream> // for std::cout
using namespace Keyzy;
std::string errorStatuses(LicenseStatus status);
int main()
{
ProductData data;
data._appId = "xxxxxxxx";
data._apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
data._productCode = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
data._cryptionKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
std::unique_ptr<KeyzyLicenseActivator> pLicenseActivator = std::make_unique<KeyzyLicenseActivator>(data);
std::shared_ptr<KeyzyLicenseValidator> pLicenseValidator = pLicenseActivator->getLicenseValidator();
LicenseStatus status = LicenseStatus::VALID;
// bring serial number input window to the user
std::string serialNumber = "";
// ------
// online
// ------
if (pLicenseValidator->validateOnline() != LicenseStatus::VALID) {
// bring serial number input window to the user
status = pLicenseActivator->activateOnline(serialNumber);
std::cout << std::endl;
std::cout << "Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
} else {
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
std::cout << "Online Validation Status: " << errorStatuses(status) << std::endl << std::endl;
}
status = pLicenseActivator->deactivateOnline();
std::cout << "Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// -----------
// semi-online
// -----------
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateSemiOnline(serialNumber);
std::cout << "Semi Online Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
}
if (status == LicenseStatus::VALID) {
// You may need to use semi-online activation without giving a serial number.
// First two cases are:
// 1- You may choose to renew weekly the offline license of the users with Semi Online activation.
// You don't want to ask the serial number again and again.
// 2- You may set Offline License Life (recommended) to 30 days. After 30 days, the offline license
// will be INVALID. Then you will need to activate it again without a serial number.
status = pLicenseActivator->activateSemiOnline();
std::cout << "Semi Online Renew Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Licensee's Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee's Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
}
status = pLicenseActivator->deactivateSemiOnline();
std::cout << "Semi Online Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// Now, the license status is not valid. The license is deleted from the device.
// If you try to use semi online activation without a serial number. You’ll have an error.
if (status != LicenseStatus::VALID) {
status = pLicenseActivator->activateSemiOnline();
std::cout << "Semi Online Renew Activation Status 2 (Error expected): " << errorStatuses(status) << std::endl << std::endl;
}
// -------
// offline
// -------
if (pLicenseValidator->validateOffline() != LicenseStatus::VALID) {
status = pLicenseActivator->activateOffline("/Users/user111/Downloads/license_file.lic");
std::cout << "Offline Activation Status: " << errorStatuses(status) << std::endl << std::endl;
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
} else {
std::cout << "Licensee Name: " << pLicenseValidator->getLicenseeName() << std::endl;
std::cout << "Licensee Email: " << pLicenseValidator->getLicenseeEmail() << std::endl;
std::cout << "Version: " << pLicenseValidator->getVersion() << std::endl;
std::cout << "Sku: " << pLicenseValidator->getSku() << std::endl;
std::cout << "License Type: " << pLicenseValidator->getLicenseType() << std::endl;
std::cout << "Start Time: " << pLicenseValidator->getStartTime() << std::endl;
std::cout << "End Time: " << pLicenseValidator->getEndTime() << std::endl;
std::cout << "Info: " << pLicenseValidator->getInfo() << std::endl;
std::cout << "Dealer Name: " << pLicenseValidator->getDealerName() << std::endl;
}
bool res = pLicenseActivator->deactivateOffline();
if (!res)
status = LicenseStatus::INVALID;
else
status = LicenseStatus::ACTIVATION_DELETED;
std::cout << "Offline Deactivation Status: " << errorStatuses(status) << std::endl << std::endl;
// ------------
// client-trial
// This trial license only stored in the client side
// There is no relationship with KEYZY servers
// ------------
if (pLicenseValidator->validateTrialLicense() != LicenseStatus::VALID) {
std::time_t t = std::time(0); // get time now
std::tm trialExpiryTime = *std::localtime(&t); // get local time
trialExpiryTime.tm_hour += 24 * 30; // add 30 days
mktime(&trialExpiryTime);
status = pLicenseActivator->activateClientTrial(trialExpiryTime);
std::cout << "Client Trial Activation Status: " << errorStatuses(status) << std::endl << std::endl;
}
bool resTrial = pLicenseActivator->deactivateClientTrial();
std::cout << "Client Trial Deactivation Status: " << resTrial << std::endl << std::endl;
}
// please find errorStatuses() function below of this page
Error function
Find the error function for all examples following.
std::string errorStatuses(LicenseStatus status)
{
switch(status) {
case LicenseStatus::EXPIRED:
return "Expired";
case LicenseStatus::INVALID:
return "Invalid";
case LicenseStatus::NOT_AUTHORIZED:
return "Not authorized";
case LicenseStatus::SERIAL_INVALID:
return "Serial invalid";
case LicenseStatus::PRODUCT_NOT_EXIST:
return "Product does not exist";
case LicenseStatus::PRODUCT_NOT_EXIST_FOR_USER:
return "Product does not exist";
case LicenseStatus::PRODUCT_NOT_ACTIVE:
return "Product is not active";
case LicenseStatus::SKU_NOT_EXIST:
return "SKU does not exist";
case LicenseStatus::SKU_NOT_ACTIVE:
return "SKU is not active";
case LicenseStatus::REACHED_MAX_NUMBER_OF_HOST:
return "Reached maximum number of host";
case LicenseStatus::PRODUCT_NOT_EXIST_FOR_SKU:
return "Product does not exist for this SKU";
case LicenseStatus::ACTIVATION_DEACTIVATED:
return "Activation is deactivated";
case LicenseStatus::SUBSCRIPTION_LICENSE_EXPIRED:
return "Subscription license expired!";
case LicenseStatus::SUBSCRIPTION_LICENSE_NOT_STARTED:
return "Subscription license not started!";
case LicenseStatus::TRIAL_LICENSE_EXPIRED:
return "Trial license expired!";
case LicenseStatus::TRIAL_LICENSE_NOT_STARTED:
return "Trial license not started!";
case LicenseStatus::CANNOT_KEEP_SERIAL:
return "Cannot keep serial!";
case LicenseStatus::CANNOT_KEEP_LICENSE_FILE:
return "Cannot keep license file!";
case LicenseStatus::ACTIVATION_DELETED:
return "Activation deleted!";
case LicenseStatus::CLIENT_SERIAL_DOES_NOT_EXIST:
return "Client serial does not exist!";
case LicenseStatus::CONNECTION_ERROR:
return "Connection Error!";
case LicenseStatus::NETWORK_DNS_FAILED:
return "Cannot reach the server. Please check your internet connection.";
case LicenseStatus::NETWORK_REFUSED:
return "Connection refused. Please check your firewall settings.";
case LicenseStatus::NETWORK_TIMEOUT:
return "Connection timed out. Please check your firewall or proxy settings.";
case LicenseStatus::NETWORK_TLS_FAILED:
return "Secure connection failed. Please check your system date/time and security software.";
case LicenseStatus::NETWORK_PROXY_REQUIRED:
return "A proxy is required. Please ask your IT to whitelist api.keyzy.io or configure proxy credentials.";
case LicenseStatus::NETWORK_HOSTS_TAMPERED:
return "Cannot verify the server address. Please check your hosts file.";
case LicenseStatus::TOO_MANY_REQUESTS:
return "Too Many Requests!";
case LicenseStatus::NO_ACTIVE_SUBSCRIPTION:
return "No Active Subscription!";
case LicenseStatus::CURRENT_LICENSE_DOES_NOT_EXIST:
return "Current license does not exist!";
case LicenseStatus::UPGRADE_LICENSE_DOES_NOT_EXIST:
return "Upgrade license does not exist!";
case LicenseStatus::UPGRADE_LICENSE_DOES_NOT_MATCH:
return "Upgrade license does not match for upgrade with current license!";
case LicenseStatus::ANOTHER_TRIAL_LICENSE_ALREADY_ACTIVATED:
return "Another trial license has already been activated on this device!";
case LicenseStatus::SKU_NUMBER_VALIDATION:
return "sku_number parameter cannot be validated!";
case LicenseStatus::PRODUCT_CODE_VALIDATION:
return "product_code parameter cannot be validated!";
case LicenseStatus::NAME_VALIDATION:
return "name parameter cannot be validated!";
case LicenseStatus::EMAIL_VALIDATION:
return "email parameter cannot be validated!";
case LicenseStatus::SERIAL_VALIDATION:
return "serial parameter cannot be validated!";
case LicenseStatus::CODE_VALIDATION:
return "code parameter cannot be validated!";
case LicenseStatus::NO_FREE_LICENSES:
return "You do not have any free licenses for this sku. Please generate new licenses for this sku!";
case LicenseStatus::NAME_OR_EMAIL_VALIDATION:
return "Either the name or email filed must be filled!";
case LicenseStatus::LICENSE_NOT_EXIST_NOT_ASSIGNED_DEALER_ALREADY_DEPOSITED:
return "The license does not exist or is not assigned to a dealer or is already deposited!";
case LicenseStatus::VALID: // Just in case
return "Valid";
default:
return "Unknown";
}
}