Click here to Skip to main content
15,906,625 members
Articles / Programming Languages / C#
Tip/Trick

Open Source .NET License Tool, EasyLicense !

Rate me:
Please Sign up or sign in to vote.
5.00/5 (20 votes)
5 Jul 2017MIT 37K   39   12
EasyLicense is an open-source license tool for .NET applications.

Introduction

I used to wonder whether there is a license tool, which makes it easy to create a license, and easy to validate the license.

Although this feature is very common when you need to license your software, I can't find a license tool, which is easy to use. Most of the license tools are too complex, and have more features, but I don't need to use them.

So I created this project to make the license process easier. Its code is short, and easy to understand.

Using the Code

Easy License is very easy to use.

To license a software, we need these three steps:

  1. Create a public/private Key:
    C#
    if (File.Exists("privateKey.xml") || File.Exists("publicKey.xml"))
    {
        var result = MessageBox.Show("The key is existed, 
        override it?", "Warning", MessageBoxButton.YesNo);
        if (result == MessageBoxResult.No)
        {
            return;
        }
    }
    
    var privateKey = "";
    var publicKey = "";
    LicenseGenerator.GenerateLicenseKey(out privateKey, out publicKey);
    
    File.WriteAllText("privateKey.xml", privateKey);
    File.WriteAllText("publicKey.xml", publicKey);
    
    MessageBox.Show("The Key is created, please backup it.");
  2. Use private key to create a license:
    C#
    if (!File.Exists("privateKey.xml"))
    			{
    				MessageBox.Show("Please create a license key first");
    				return;
    			}
     
    			var privateKey = File.ReadAllText(@"privateKey.xml");
    			var generator = new LicenseGenerator(privateKey);
     
    			var dictionary = new Dictionary<string, string>();
     
    			// generate the license
    			var license = generator.Generate("EasyLicense", Guid.NewGuid(), 
                                                  DateTime.UtcNow.AddYears(1), dictionary,
    				                              LicenseType.Standard);
    			
    			txtLicense.Text = license;
    			File.WriteAllText("license.lic", license);
  3. Use public key to validate the license:
    C#
    private static void ValidateLicense()
    		{
    			if (!File.Exists("publicKey.xml"))
    			{
    				MessageBox.Show("Please create a license key first");
    				return;
    			}
    			
    			var publicKey = File.ReadAllText(@"publicKey.xml");
     
    			var validator = new LicenseValidator(publicKey, @"license.lic");
     
    			try
    			{
    				validator.AssertValidLicense();
    			}
    			catch (Exception ex)
    			{
    				Console.WriteLine(ex.Message);
    			}

Points of Interest

All these functions are provided by a LicenseTool tool, you can download the source, and run this tool to see how EasyLicense creates, validates a license.

Image 1

To validate the license, I create a demo project:

Image 2

Git

License

Image 3

History

add Rhino Licensing author mail.

  • 4th July, 2017: Initial version
  • Add Rhino-licensing author mail.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Question[My vote of 1] Plagiarism- copy from Rhino license. Sorry please remove this article Pin
FatCatProgrammer5-Jul-17 3:12
FatCatProgrammer5-Jul-17 3:12 
AnswerRe: [My vote of 1] Plagiarism- copy from Rhino license. Sorry please remove this article Pin
LoveJenny5-Jul-17 14:38
LoveJenny5-Jul-17 14:38 
GeneralRe: [My vote of 1] Plagiarism- copy from Rhino license. Sorry please remove this article Pin
paksys7-Jul-17 16:46
paksys7-Jul-17 16:46 
QuestionCopying rhino-licensing Pin
forgetuu4-Jul-17 20:07
forgetuu4-Jul-17 20:07 
AnswerRe: Copying rhino-licensing Pin
BillWoodruff4-Jul-17 22:51
professionalBillWoodruff4-Jul-17 22:51 
AnswerRe: Copying rhino-licensing Pin
LoveJenny5-Jul-17 15:03
LoveJenny5-Jul-17 15:03 
GeneralRe: Copying rhino-licensing Pin
forgetuu5-Jul-17 17:10
forgetuu5-Jul-17 17:10 
GeneralRe: Copying rhino-licensing Pin
LoveJenny5-Jul-17 18:17
LoveJenny5-Jul-17 18:17 
QuestionPlease look rhino-licensing Pin
VAllens3-Jul-17 18:58
VAllens3-Jul-17 18:58 
AnswerRe: Please look rhino-licensing Pin
BillWoodruff4-Jul-17 22:52
professionalBillWoodruff4-Jul-17 22:52 
AnswerRe: Please look rhino-licensing Pin
ThePhoenyx7-Jul-17 7:45
ThePhoenyx7-Jul-17 7:45 
GeneralRe: Please look rhino-licensing Pin
LoveJenny10-Jul-17 1:03
LoveJenny10-Jul-17 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.