You are here
Home > Reviewed > CryptoLicensing For .Net – License Your Software

CryptoLicensing For .Net – License Your Software

Fallback Image

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

  • 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

crypto license settings set

  • 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.

Dirk Strauss
Dirk is a Software Developer and Microsoft MVP from South Africa. He loves all things Technology and is slightly addicted to Twitter and Jimi Hendrix. Apart from writing code, he also enjoys writing human readable articles. "I love sharing knowledge and connecting with people from around the world. It's the diversity that makes life so beautiful." Dirk feels very strongly that pizza is simply not complete without Tabasco, that you can never have too much garlic, and that cooking the perfect steak is an art he has yet to master.

Similar Articles

  • Hello Ben. The article just included the license key as a constant string for illustration purposes. In reality though, you would generally provide this license key to your users via a secure method (not email obviously). There are many ways to do this, but what I would do for example is create a license server application. The license server has a single job and that is to store newly created licenses per customer/app/instance or which ever way suits you. I would then probably expose a public facing area of the license server via a web application and allow the customer to log on. Obviously the license server will need to use encryption and best practices for storing the customer logon data. Then they can log on to their portal and get the licenses as needed. On your side, what you will need to do is create some sort of integration to the license server (not public facing) that will generate the license code and store it on the license server. It then fires off an email to the customer telling them that their product license can be found on the portal after logging in. A nice benefit of this is that the license key is never transmitted over the wire. It remains on your server that you control. You can also brand the customer portal nicely with your company/application branding.

    Again, the method above is rather simple in its approach and there might be better ways of implementing this. This is but one way of doing it.

Top