Skip to main content
This older tutorial shows a basic VB.NET desktop integration. The examples below verify online at registration and startup. For cached offline use, follow the offline verification guide.
In this tutorial, we’ll add licensing to an existing VB.NET Windows Forms application in Visual Studio. The screenshots show an older version of Visual Studio. If you are using another language, please see the SDK guides.
If you want to jump straight into the code, please check out the key verification tutorial.
Digitaltools All Features Pn
The example has three features (voice, audio, and converter). Features 1, 2, and 3 enable their buttons. Feature 4 marks a time-limited license; without it, this example treats the license as perpetual.

Cryptolens .NET Client

Now we can start using all of the power of the Cryptolens Client API. The easiest way to get Cryptolens Client API is through NuGet in Visual Studio.
  1. Go to the solution explorer and right click on the project (not the solution).
  2. Click on Manage NuGet Packages...
Vs Nuget 1 Pn Now, type Cryptolens.Licensing into the Browse tab, select SKM Client API and install it. Vs Nuget 2 Pn

Adding Code

We almost have all the pieces in place to get a working licensing solution. We will cover the code in this section and look at how to retrieve access tokens and public key (RSA) later. Our application will have two places where we will need to insert the code:
  • During license key registration - the first time the user inserts a license key
  • During application start - to check for an existing license on launch
The original Digital Tools project shows the desktop UI. Use the updated licensing snippets below when adapting it.
Note, you can find more detailed examples of .NET here and other environments here. Please don’t hesitate to contact us should you have any questions.
Add these imports at the top of your main form’s code file:
Add the following inside the main form class. NoLicense disables the three feature buttons until a license has been verified.
The examples use product ID 3349. Replace it with your product ID in both the request and the response check. You will also need an access token with the Activate permission and your RSA public key; the sections below explain where to find them. For node-locked licensing, set Maximum Number of Machines greater than 0. This example does not use floating seats.

License Key Registration

Put this code in your license-entry button’s Click handler on the main form. TextBox1 contains the entered license key, and Button1, Button2, and Button4 are the feature buttons in the example. Replace these control names if your form uses others.
This code activates the license, verifies the signature, and enables the buttons for features 1, 2, and 3. Feature 4 indicates a time limit. Once the checks pass, SaveToFile() saves the signed response to licensekey.skm, ready for the next startup. You can pass a different path to both SaveToFile and LoadFromFile if needed.

Application Start

Put this code in the same form’s Load handler. We load the saved file to find the license key, then activate it again to get any changes made since the last run.
If no key has been saved or verification fails, the feature buttons remain disabled. The user can enter a key and try again. Check expiry when the user starts a feature too, since the application may have stayed open past the expiry date. For example, begin Button1_Click with:
For long-running work, recheck expiry while it runs. To add scheduled online refresh and offline use, follow the offline verification flow, choosing your own cache storage and maximum offline age. Keep its distinction between connectivity failures and explicit rejections.

Access Tokens

In all of the code examples, you will see variables such as token or auth. They refer to an access token. The idea behind access tokens is to allow you to:
  • identify yourself with Cryptolens (authentication) - let Cryptolens know that you are you
  • give your application only the permissions it needs (authorization) - for example, access to particular methods or products
An access token should only have the permissions your application needs. For example, one access token can have both the Activate and Deactivate permissions if the application registers and releases devices. The access token guide has examples and explains the Product, Key, and Feature Lock settings.

Creating a new Access Token

In order to create an access token with the permission required by the previous example:
  1. Go to ‘Your account name’ (right corner) > ‘Access Token’.
  2. Click on ‘Create new Access Token’. You will now be on this page.
  3. Enter a name, such as “ActivateToken”.
  4. Select the Activate permission under License Key. Add the Deactivate permission if your application releases devices and the Get Key permission if it calls GetKey.
  5. Select the ‘Product Lock’ to be the name of your application.
  6. Leave Key Lock and Feature Lock at 0 for this starting configuration, then select Create Access Token.
  7. Copy and securely store the access token when it is shown, then replace the example’s access token with yours. The value cannot be retrieved later.

Example

You can find an example configuration in Application activation and device release.

Public Key

In many cases, you will store license key data locally on your customers’ devices, partly to allow your customers to use the application offline. At the same time, you don’t want them to be able to modify the license key data (for example, the features they are entitled to and the expiration date). Therefore, Cryptolens will sign the license key (if you explicitly tell it to do so) with your private key. The public key will allow your application to check that the license key file hasn’t been modified since it was signed by Cryptolens. The public key won’t allow them to re-sign the data, only to validate it.

Finding your Public Key

In order to find your unique public key:
  1. Sign in to the dashboard QuickStart page and find Credentials → RSA Public Key.
  2. Copy the entire public key, including the XML tags, into the RSAPubKey variable in both examples.
See Where do I find my RSA public key? for details. The public key verifies signatures; the access token authorizes API calls.

Create a Key

We’re now ready to test the code using your account.
  1. Select the product from the list.
  2. Click on ‘Create a new Key’.
  3. Check features 1, 2, and 3 for the functionality to enable.
  4. For this example’s time-limited policy, check feature 4 and set the expiry date.
Use a license from your own product with the corresponding account credentials. Test feature access, an expired time-limited license, a blocked license, and a failed connection before publishing.

Done!

You now have a basic online activation check for registration and startup, with feature access controlled by the verified license.

Next steps

Before publishing, review the publishing checklist. You can then add:
  1. Get started with payment forms
  2. Learn more about possible licensing models
  3. Understand GDPR and its implications