CryptoLicensingCryptoLicensing – In a previous article I talked about Crypto Obfuscator For .Net which obfuscates your source code allowing you to protect your intellectual property.

As part of this first line of defense, you need to enable licensing in your commercially available software. CryptoLicensing from LogicNP Software is a very good and feature packed licensing tool.

Enabling the logic in your code is really easy. Follow along with the code samples below.

CryptoLicensing – Add License Valiation Easily

When you start CryptoLicensing, you need to specify where to create a new License Project. This project you will never make publicly available and needs to be secured from prying eyes. You will generally treat this like you do your unobfuscated source code.

CryptoLicensing

As a quick start, after saving your project, click on the ‘Project’ menu and select to get a validation key and code.

CryptoLicensing

The validation key will be displayed to you in a separate window along with a bit of sample source code.

CryptoLicensing

Heading over to Visual Studio, add a reference to the LogicNP.CryptoLicensing dll.

CryptoLicensing

After adding it, you will see it available under your references in the solution explorer.

CryptoLicensing

Next, add a new class called ‘LicenseValidation.cs’ to your project.

license validation class

In the new class, add a Validate method that uses the validation key provided by the CryptoLicensing application above. Allow the constructor to take the license code as parameter.

CryptoLicensing

Moving back to the CryptoLicensng tool, you can see that every new CryptoLicensing project comes with two default profiles (Normal License or 30-day evaluation license). CryptoLicensing allows you to create multiple profiles and associate different settings for each profile. This allows you to quickly generate a license based on the specific profile you select. For this example,we’ll just use the default normal license.

license type

Click on the ‘Generate’ button.

license code

This will generate as many codes for you as you specify in the codes count next to the ‘Generate’ button.

generate code

These are the codes you will be giving to the users of your software.

call code sample

In the Program.cs file of your application, you will generally read the user license from a file or an application setting or some other store. For the purposes of this example, I’ll just hard code it in the app. The static void main uses the license code provided by the user and validates this against the LicenseValidation class created earlier. If the license is valid, the application will run. If not, a warning message is displayed to the user.

CryptoLicensing – Add License Features Easily

Sometimes you will activate certain features in your application, based on the license type you provide. For this example, let’s use the previously written weather forecast app and assume that there is an additional license that allows the user to view a five day forecast.

crypto license features rename

Select one of the feature slots available.

crypto license rename feature

You can now rename the feature slot to make it easier to identify later on.

crypto license featured renamed

Select the new feature and generate a new license code.

crypto license change license dll

Modify the LicenseValidation class we created earlier and create an enum for the feature types (This also makes the features more easily referenced). Move the CryptoLicense object outside the scope of the Validate method to make it visible to the rest of the class.

crypto license add feature method

Add a new method to the LicenseValidation class that checks if the specific feature is present. This method will simply return a boolean value.

crypto license enable button

In the constructor of the main form, add a boolean parameter that will enable or disable the button that displays the five day forecast.

crypto license change progrem cs

In the Program.cs file, change the code slightly to pass the result from the ‘EnableFiveDayForecast’ method to the main form’s constructor.

crypto license button enabled

Running the application with a license that includes the five day forecast functionality, you will notice that the button is enabled.

crypto license disable feature

Back in the CryptoLicensing tool, unselect the ‘5 Day Forecast’ feature and generate a new user license code. Paste that in your Program.cs file and run your application again.

crypto license button disabled

This time you will see that the feature was not validated and the button is disabled. This example might be a bit granular for many applications, but I wanted to highlight this functionality specifically. I would generally just define a version of the software (Standard, Professional, Enterprise etc.) and enable or disable a collection of features at a time.

CryptoLicensing – Other Settings

CryptoLicensing is truly a feature rich tool. You can specify the following:

crypto license settings set

crypto license settings set

This is a tool that is definitely worth checking out. It is really easy to integrate with your existing software and provides excellent management of your licenses. To fully appreciate all the features of CryptoLicensing For .Net, download an evaluation copy and try it out for yourself.