Skip to main content
The code below should be included whenever you want to verify a license key, which normally occurs during app start (eg. Form_Load for desktop apps). In addition, you can invoke it whenever a user updates the license key. In some licensing models, this check needs to be called periodically.

Getting started

1

Add client SDK/library

First, we need to install the client SDK / library
  • C#/VB.NET
  • Python
  • Java
  • Node Js
  • Go
  • C++

Install Nuget package

In Visual Studio package manager
PM> Install-Package Cryptolens.Licensing
Using dotnet CLI
dotnet add package Cryptolens.Licensing
If you are targeting Mac, Linux or Unity/Mono, we recommend to use the cross platform version of that package.In Visual Studio package manager
PM> Install-Package Cryptolens.Licensing.CrossPlatform
Using dotnet CLI
dotnet add package Cryptolens.Licensing.CrossPlatform
2

Add namespace

using SKM.V3;
using SKM.V3.Methods;
using SKM.V3.Models;
3

Add key verification script

The following script will verify the license key with the server. To get it to work, you need to change the ProductId, the RSAPubKey, Access Token and licenseKey. More information can be found below the code snippet.
var licenseKey = "GEBNC-WZZJD-VJIHG-GCMVD"; // <--  remember to change this to your license key
var RSAPubKey = "enter the RSA Public key here";

var auth = "access token with permission to access the activate method";
var result = Key.Activate(token: auth, parameters: new ActivateModel()
{
    Key = licenseKey,
    ProductId = 3349,  // <--  remember to change this to your Product Id
    Sign = true,
    MachineCode = Helpers.GetMachineCodePI(v: 2)
});

if (result == null || result.Result == ResultType.Error ||
    !result.LicenseKey.HasValidSignature(RSAPubKey).IsValid())
{
    // an error occurred or the key is invalid or it cannot be activated
    // (eg. the limit of activated devices was achieved)
    Console.WriteLine("The license does not work.");
}
else
{
    // everything went fine if we are here!
    Console.WriteLine("The license is valid!");
}

Console.ReadLine();
.NET(C#/VB.NET) only: If your application will run in Unity/Mono, Rhino/Grasshopper or on a platform other than Windows, we recommend to use a different version of Key.Activate.
RSAPubKey is found at the bottom of this page, under RSA Public Key section and it’s the same for the entire account. You don’t need to change it.Access token can be created on this page. For the code to work, please check “Activate” permission and leave other fields unchanged. Typically, an access token stays the same for all your products, however, you can always create a new one and make it product specific.ProductId is found on the product page and if you add the key verification script to a new product, this value needs to be changed in the code.LicenseKey is found on the product page and contains 20 characters of the following format AAAA-BBBB-CCCC-DDDD. Each end user/customer should normally receive their unique license key. The license key should not be hard coded inside the application. Instead, there should be a way for the user to enter it inside the application or other means.
Using license keys is only one of the way to authenticate customers. You can also use license files (see Offline verification tutorial for more information) as well as username and password (see User verification tutorial).

Troubleshooting

General

In most cases, this is because some of the required parameters are missing. These are:
  • RSAPubKey
  • auth
  • ProductId
It can also be that the licenseKey is missing. Please check the beginning of the tutorial on how to find them.
Note, if you have blocked a license key, it will also return a null result.

.NET specific (C#/VB.NET)

In some Windows environments (e.g. when developing Excel addins), it might not be feasible to call Helpers.GetMachineCode on .NET Framework 4.6. The reason for this is the call we make to System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform. To fix this, we have added a boolean flag in Helpers class. Before calling Helpers.GetMachineCode or Helpers.IsOnRightMachine, please set Helpers.WindowsOnly=True.
Helpers.WindowsOnly = true;
var machineCode = Helpers.GetMachineCode();
If the approach above does not work, please try the following call instead:
var machineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
This means that Cryptolens.Licensing library was not included into the project. It can be easily added using NuGet packager manager, which you can find by right clicking on the project:Nuget Vs2017 Example Pn
If you are
If your clients are able to visit app.cryptolens.io and api.cryptolens.io in Microsoft Edge but unable to activate the application, the issue could be both that they are using a proxy, connect to Active directory or that their IT department has blocked TLS of certain versions.To fix these issues, we recommend to:
  1. Update to the latest version of the SDK.
  2. If you run a version of .NET Framework prior to .NET Framework 4.7, we recommend to manually specify which TLS should be used. Before any call to the API (for instance, Key.Activate performs an API call), we recommend to add the following line:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Ideally, you should try to pick the highest available TLS version, but it is important to also test that such TLS version is supported in the .NET Framework vesion that you use.If possible, the best approach is to run the latest version of .NET Framework. If that is not possible, please use at least .NET Framework 4.7. In other cases, the workaround above can be used (i.e. manually specifying the TLS version).
Some customers have reported an error with the right version of Newtonsoft.Json not being found. It seems to be localized to those that target .NET Framework 4.8, and the following error is shown:
System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
The error is thrown when a wrong version of Newtonsoft.Json is installed in the same project as Cryptolens.Licensing library. To fix this, you need to make sure that Newtonsoft.Json is uninstalled completely and then re-install Cryptolens.Licensing.

Python

This error occurs when the timestamp for the expiration date received from the server exceeds the limit in Python. This typically occurs when the Period is set to a excessively large value, often to prevent the license from expiring.While Cryptolens requires a period (defaulted to 30) during the creation of a new license, this does not mark the license as time-limited. You can learn more about it here. In essence, a license is treated as time-limited by either enforcing this in the Python code (e.g. if F1=true, the license is time-limited and so we check the expiration date against the current date, to see that it is still valid) or on the server side. On the server side, you can, for example, set up a feature that will automatically block expired licenses. You can read more about it here.In sum, to solve this issue, you can either follow one of the methods described above or set the period to a smaller value.
This error is thrown when the urllib library (a built in library in Python that we use to send HTTP requests) is unable to locate the CA files on the client machine. From our experience, this error occurs exclusively on Macs where the Python environment is incorrectly installed.To solve this temporarily for testing purposes, you could temporary disable SSL verifications as described in here, however, we do not recommend this in a production scenario. Instead, a better solution is to fix the underlying issue preventing the Python environment from finding the CA files.This can be accomplished in at least two ways:Using certifiBefore calling any of the API methods (e.g. Key.activate), you can add the following code:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
Please note that this requires certifi package to be installed.Running a script in the Python environmentAn alternative is to run script in their environment that should fix the issue. You can read more about it in this thread: #65SummaryThe key takeaway is that it is better to address the issue with missing CA on the user side, since this issue will typically be user-specific. If that is not possible, you can use the code above to manually set the path to CA files. Although we have mentioned turning off SSL verification temporarily, it should not be used in production. Key.activate takes care of signature verification internally, but some other methods do not.
If you have customers who want to use a proxy server, we recommend enabling the following setting before calling any other API method, such as Key.Activate.
HelperMethods.proxy_experimental = True
This will ensure that the underlying HTTP library (urllib) used by Cryptolens Python SDK will use the proxy configured on the OS level. The goal is to make this default behaviour in future versions of the library, once enough feedback is collected.
SSL verification can temporarily be disabled by adding the line below before any call to Key.Activate.
HelperMethods.verify_SSL = False
The Cryptolens Python SDK will verify that the license information has not changed since it left the server using your RSA Public Key. However, we recommend to keep this value unchanged.

C++

How errors are reported in the C++ library is described in the README.md file, which is also available here.
I