Licensing by secure encrypted license keys provides an easy way to activate application or control from evaluation to full functional version. Manco.Licensing uses a public key encryption to generate and verify encrypted license keys. This schema is more suitable for licensing .NET applications, but you can use it to license .NET controls as well.
Usually programmers like following behavior for the copy-protected application that uses “Unlock Key” licensing schema:
Let see how it works in .NET Licensing Pro.
The evaluation status of the application is defined by including “Is Evaluation” field to the license type.
The time\running limit is defined by including one of the following “Expiration Dates”, “Expiration Date” or “Expiration Runs” fields to the license type.
The “Unlock Key” field should be included to the license type to force protection library check Unlock Key.
The “Write Key to File” should be included to force protection library write entered “Unlock Key” to the license storage.
If “Is Evaluation” field is included to the License type, the license will be valid (evaluation license is valid license) but have evaluation status. Evaluation status of the license can be checked using license.IsEvaluation property of license object. This status can be used to limit functionality of the application in evaluation mode.
If one of the time\running limit fields has been included to the license type, then application will work till expiration come. Depends on the settings license object can throw exception or set expired status on license. Expiration status of license can be checked using license.IsExpired property.
If unlock key has been entered and it is valid unlock key, then evaluation and expiration statuses will be removed and license become valid. If wrong unlock key has been entered license become invalid.
So, license that uses “Unlock Key” schema can be:
If you suppose to createnewProduct->Version->List of License Types chain, then the easiest way is to use “New Product Wizard” (see Quick Start). To allow you product use “Unlock Key” licensing schema you should include “License activated by unlock key” predefined type into the license types will be used with your product.
If you suppose to createallProduct->Version->List of License Types chain manually (see "Create New Product manually", Create New Version manually, Create License Type manually sections in help or documentation) or if you have created Product, Version and License Type already, then you can prepare corresponding license type manually. To make license type ready to accept license keys do following steps:
Now you should prepare your code to accept license key. If your product is desktop application, then you can allow your users enter unlock key through special window form or using some kind of the configuration file. In any case you should put entered key to the “UnlockKey” property of the license object (see Quick Start). This code should be located before first license validation. It seems that OnLoad event handler of your main form is a good location. Your code could looks like the following:
[C#] // Check if the current license is expired or is evaluation license // Because of the code optimization made by .NET when check // conditional expressions the IsExpired should be placed // on the first place. if (license.IsExpired || license.IsEvaluation) { // This is evaluation license, so // we should show license dialog LicenseForm loForm = new LicenseForm(); loForm.License = license; if (loForm.ShowDialog() == DialogResult.OK && loForm.UnlockKey.Trim() != string.Empty) { // License information have been entered. // Pass it to the license object for the // following validation. license.UnlockKey = loForm.UnlockKey; } else if (license.IsExpired) { // The evaluation license has been expired and // no license information have been entered, // so we should close application. Application.Exit(); } } // Now you can use license object to validate license provided with product. // It could be unlock key or license file, in any case validation should be done by // checking IsValid property of the license object. // License will be valid if it is evaluation license, // or entered valid Unlock Key. if (license.IsValid) { // Initialize application // … } else { // License not valid – wrong unlock key has been entered // or wrong license file is used MessageBox.Show("License Not Valid", "Sample Application", MessageBoxButtons.OK, MessageBoxIcon.Stop); Application.Exit(); } [Visual Basic .NET] ' Check if the current license is expired or is evaluation license ' Because of the code optimization made by .NET when check ' conditional expressions the IsExpired should be placed ' on the first place. If license.IsExpired Or license.IsEvaluation Then ' This is evaluation license, so ' we should show license dialog Dim loForm As LicenseForm = New LicenseForm() loForm.License = license If loForm.ShowDialog() = DialogResult.OK _ And loForm.UnlockKey.Trim() <> String.Empty Then ' License information have been entered. ' Pass it to the license object for the ' following validation. license.UnlockKey = loForm.UnlockKey ElseIf license.IsExpired Then ' The evaluation license has been expired and ' no license information have been entered, ' so we should close application. Application.Exit() End If End If ' Now you can use license object to validate license provided with product. ' It could be unlock key or license file, in any case validation should be done by ' checking IsValid property of the license object. ' License will be valid if it is evaluation license, ' or entered valid Unlock Key. If license.IsValid Then ' Initialize application ' … Else ' License not valid – wrong unlock key has been entered ' or wrong license file is used MessageBox.Show("License Not Valid", _ "Sample Application", _ MessageBoxButtons.OK, _ MessageBoxIcon.Stop) Application.Exit() End If
Note. Pay attention that we check license expiration status (license.IsExpired) in the code. It means that we wouldn’t like license object through an exception if license is expired during object initialization. To avoid license object throw an exception find implementation of the “BypassExpirationCheck” property in your code and change it to return true value.
[C#] /// <summary> /// Indicates whether the expiration check should be performed /// inside the license constructor. /// </summary> public bool BypassExpirationCheck { get { // Default return value is false. We change it to true // so we could bypass expiration check in the constructor // of the license object so it wouldn't throw exception // and we could use license object to show license information // in the license dialog. return true; } } [Visual Basic. NET] ''' <summary> ''' Indicates whether the expiration check should be performed ''' inside the license constructor. ''' </summary> Public ReadOnly Property BypassExpirationCheck() As Boolean _ Implements Manco.Licensing.ILicenseKeyProvider.BypassExpirationCheck Get ' Default return value is false. We change it to true ' so we could bypass expiration check in the constructor ' of the license object so it wouldn't throw exception ' and we could use license object to show license information ' in the license dialog. Return True End Get End Property
We leave implementation of the LicenseForm on your own, so you can put anything you’d like to it. The simple form can contain some kind of the notification text and text field with length enough to enter 95 characters of the unlock key (80 hexadecimal digits with dash after every fifth digit). You should provide a way to get entered key from the form and put it to the “UnlockKey” property of the license object.
Now you are ready to start issuing the unlock keys. At the first, you should create one purchase licensed for you and leave it with empty “Unlock Key” field. This purchase will be source of the evaluation license file will be provided with your application. It will be single license file you will create for your product, but it should exists and be located in the License folder near you product executable. Field “Unlock Key” in this file should be empty. Put marker to the license type has been prepared for accepting “Unlock Key”. Create new purchase for it:
. Fill customer’s information with information about your company. Don’t generate unlock key for this purchase. Your purchase information with empty key could looks like following:
After that you should save information about this purchase (with empty “Unlock Key” attribute) to the license file. To perform this operation you should do one of the following:
. You will see standard file dialog. Select proper location and save license file there. Don’t forget include this license file for your product distribution.
Now you are ready to issue unlock keys for your product. You can generate unlock keys without entering information about purchase, but we recommend you track unlock keys issuing with entering information about purchases. So, to generate unlock key for single customer has paid for your product you need put marker to the corresponding license type node in the product tree view and create new purchase:
. Fill in information about customer. If you think, that this customer already bought something from you before, then you can fill just part of the information and perform search of the customer:
. Many, one or no one customers could be found. In case when we have list of customers you will see the following dialog:
Select customer by checking corresponding checkbox and click “OK”. Or click “Cancel” if there is not customer meet you needs in the list.
In case when only one customer has been found, the customer information fields will be filled with corresponding information. No dialogs or messages would be shown.
In case when no one customer has been found you will see message box with following text: “No one Customer has been found for a given criteria. This customer will be marked as a new one.”
Generate “Unlock Key” for this purchase:
. Finally view for a new purchase will looks like the following:
Copy the unlock key from the “Unlock Key” field and paste it to the message you will send to your client.
If you’d like to create unlock keys without entering information about purchases (to send them to separate distributor, for example) you can do the following: put marker to the license type you’ve prepared to accept unlock keys. Then do one of the following:
You will see the following dialog
Enter number of keys you need and click “Generate” number.
Note: Generation of big number of keys takes a long time.
When generation will be finished you can click “To Clipboard” button to get keys have been generated to the clipboard. After that you can paste keys where you need (to the text of e-Mail, for example). Click “OK” to close dialog.