Open Source .NET License Tool, EasyLicense !

0
28

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:

    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:
    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>();
 
 
 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:
    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.

To validate the license, I create a demo project:

Git

License

History

add Rhino Licensing author mail.

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

LEAVE A REPLY