.NET desktop application
An older tutorial on how to integrate Cryptolens licensing into a desktop application in .NET
This is an old tutorial that we have kept that shows how you can implement basic license verification in a .NET application. We recommend to review our Getting Started Guide and refer to our key verification tutorial for production ready examples.
Our aim of this tutorial is to guide you through, step by step, the process of implementing Cryptolens into your application. We’ll assume that you’ve developed a .NET application and use Visual Studio 2013. If you are using a different language, we recommend to check out this page.
If you want to jump straight into the code, please check out the key verification tutorial.
Our application will have three features (voice, audio and converter), and the ability to license these as a ‘subscription’ (time-limited) or ‘perpetual’ (unlimited time). We will check the license key when we have an Internet connection. If we’re offline, we will use the saved license file. The user will be able to use the software 90 days offline at most.
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.
- Go to the solution explorer and right click on the project (not the solution).
- Click on
Manage NuGet Packages...
Now, type Cryptolens.Licensing
into the Browse tab, select SKM Client API
and install it.
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 existing license on launch
You can download the source code here.
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.
License Key Registration
This code will retrieve all the license data (using Refresh
) and enable buttons depending on the features in the license. Features 3-5 indicate a certain functionality whereas Feature 1 is used to indicate a time-limit (in case it’s a subscription). Once we have a valid license, we will save it locally (it will be signed by SKM, because sign is set to true in Refresh
).
Application Start
When your application launches, we will try to get a new version of the license key, in case it has been modified. If we don’t have internet access, we will use the local copy as long as 90 days have not passed since it was retrieved. Everything else is the same as when the user registers the license for the first time.
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
- make sure only desired permission is given to something (authorization) - eg. method scope, product, etc.
Using an access token, you can specify the methods you want to be able to call, the product you want to use, the license key, and optionally feature you want to change. You can read more about them here.
Creating a new Access Token
In order to create an access token with the permission required by the previous example:
- Go to ‘Your account name’ (right corner) > ‘Access Token’.
- Click on ‘Create new Access Token’. You will now be on this page.
- Enter a name, such as “ActivateToken”.
- Check the ‘Activate’ box (under LicenseKey)
- Select the ‘Product Lock’ to be the name of your application.
- Press ‘Create an Access Token’.
- Copy the access token and replace our token with yours.
Example
Public Key
In many cases, you will store license key data locally on your customers’ device, 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 number of features they are entitled to and 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 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:
- In the menu in the right corner (with your name), select ‘Security Settings’.
- Copy the entire public key and replace it with yours (in the
publicKey
variable).
Create a Key
We’re now ready to test the code using your account.
- Select the product from the list.
- Click on ‘Create a new Key’.
- Check features 3,4,5.
- Optionally, if you want to have a time limit, check feature 1 too.
In case you kept the code as it is (without replacing the token and pubkey with yours), you can test the following:
IWXAZ-FVMOD-KBZQU-DKUFW
- all features in one years since this tutorial was writtenIYVOO-JCWXQ-LCRBI-ZAIQZ
- all features but the recorder with no time constraint.
Done!
You have successfully completed this tutorial! If you would have any questions, please get in touch us with us using chatbox available on each page.
Good luck!
Next steps
You’ve now implemented Cryptolens into your application. Here’s what’s next: