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.
As a quick start, after saving your project, click on the ‘Project’ menu and select to get a validation key and code.
The validation key will be displayed to you in a separate window along with a bit of sample source code.
Heading over to Visual Studio, add a reference to the LogicNP.CryptoLicensing dll.
After adding it, you will see it available under your references in the solution explorer.
Next, add a new class called ‘LicenseValidation.cs’ to your project.
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.
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.
Click on the ‘Generate’ button.
This will generate as many codes for you as you specify in the codes count next to the ‘Generate’ button.
These are the codes you will be giving to the users of your software.
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.
Select one of the feature slots available.
You can now rename the feature slot to make it easier to identify later on.
Select the new feature and generate a new license code.
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.
Add a new method to the LicenseValidation class that checks if the specific feature is present. This method will simply return a boolean value.
In the constructor of the main form, add a boolean parameter that will enable or disable the button that displays the five day forecast.
In the Program.cs file, change the code slightly to pass the result from the ‘EnableFiveDayForecast’ method to the main form’s constructor.
Running the application with a license that includes the five day forecast functionality, you will notice that the button is enabled.
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.
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:
- The number of users in the license
- Detection for date rollback
- Detect if your software is running under a debugger or tracer
- Detect and prevent your application from running in a remote desktop, terminal services or Citrix
- Explicitly set the ID instead of letting CryptoLicense do it for you
- Force an expiration date
- Various settings for evaluation software
- Specify a license that is locked to a specific machine
- Specifies that the license requires activation via a license server
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.