Standard.Licensing 1.1.5

.NET Standard 1.0 .NET Framework 4.0
Install-Package Standard.Licensing -Version 1.1.5
dotnet add package Standard.Licensing --version 1.1.5
<PackageReference Include="Standard.Licensing" Version="1.1.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Standard.Licensing --version 1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Standard.Licensing, 1.1.5"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Standard.Licensing as a Cake Addin
#addin nuget:?package=Standard.Licensing&version=1.1.5

// Install Standard.Licensing as a Cake Tool
#tool nuget:?package=Standard.Licensing&version=1.1.5
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

NuGet NuGet Build status

About

Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and Xamarin products.

This is project is derived from Portable.Licensing library. The purpose of this fork is to add support for more .NET platforms, especially .NET Standard and .NET Core.

There is also a plan to decouple from Bouncy Castle library and use System.Security.Cryptography.Cng for modern .NET platforms.

Installation

Get Standard.Licensing from nuget.

PM> Install-Package Standard.Licensing

Usage

Create a private and public key for your product

Standard.Licensing uses the Elliptic Curve Digital Signature Algorithmus (ECDSA) to ensure the license cannot be altered after creation.

First you need to create a new public/private key pair for your product:

var keyGenerator = Standard.Licensing.Security.Cryptography.KeyGenerator.Create(); 
var keyPair = keyGenerator.GenerateKeyPair(); 
var privateKey = keyPair.ToEncryptedPrivateKeyString(passPhrase);  
var publicKey = keyPair.ToPublicKeyString();

Store the private key securely and distribute the public key with your product. Normally you create one key pair for each product, otherwise it is possible to use a license with all products using the same key pair. If you want your customer to buy a new license on each major release you can create a key pair for each release and product.

Create the license generator

Now we need something to generate licenses. This could be easily done with the LicenseFactory:

var license = License.New()  
    .WithUniqueIdentifier(Guid.NewGuid())  
    .As(LicenseType.Trial)  
    .ExpiresAt(DateTime.Now.AddDays(30))  
    .WithMaximumUtilization(5)  
    .WithProductFeatures(new Dictionary<string, string>  
        {  
            {"Sales Module", "yes"},  
            {"Purchase Module", "yes"},  
            {"Maximum Transactions", "10000"}  
        })  
    .LicensedTo("John Doe", "john.doe@example.com")  
    .CreateAndSignWithPrivateKey(privateKey, passPhrase);

Now you can take the license and save it to a file:

File.WriteAllText("License.lic", license.ToString(), Encoding.UTF8);

or

license.Save(xmlWriter);

Validate the license in your application

The easiest way to assert the license is in the entry point of your application.

First load the license from a file or resource:

var license = License.Load(...);

Then you can assert the license:

using Standard.Licensing.Validation;

var validationFailures = license.Validate()  
                                .ExpirationDate()  
                                .When(lic => lic.Type == LicenseType.Trial)  
                                .And()  
                                .Signature(publicKey)  
                                .AssertValidLicense();

Standard.Licensing will not throw any Exception and just return an enumeration of validation failures.

Now you can iterate over possible validation failures:

foreach (var failure in validationFailures)
     Console.WriteLine(failure.GetType().Name + ": " + failure.Message + " - " + failure.HowToResolve);

Or simply check if there is any failure:

if (validationFailures.Any())
   // ...

Make sure to call validationFailures.ToList() or validationFailures.ToArray() before using the result multiple times.

Credits

License

This project is licensed under MIT License.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net40 net403 net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Windows Phone wp8 wp81 wpa81
Windows Store netcore netcore45 netcore451
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 1.0

  • .NETStandard 1.3

  • .NETStandard 2.0

    • No dependencies.
  • Portable Class Library (.NETFramework 4.0.3, Silverlight 5.0, Windows 8.0, WindowsPhone 8.0)

    • No dependencies.
  • Portable Class Library (.NETFramework 4.5, Windows 8.0, WindowsPhone 8.0, WindowsPhoneApp 8.1)

    • No dependencies.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on Standard.Licensing:

Package Downloads
FenixAlliance.ACL.Dependencies

Application Component for the Alliance Business Suite.

BlackStar.Model

BlackStar is a general APS (advanced planning & scheduling) model and algorithm solution for various industries including aerospace mission, unmanned systems and vehicle fleets. BlackStar uses a continuous time model for precision events, covering routing, dispatching and time window optimizing. Project URL - https://github.com/AnakinCN/BlackStar-APS. Contact anakin@seeingstones.cn for license application.

Monotype.Core The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

This is the core library for monotype web publishing tool, please use Monotype package instead.

DevAttic.Hive.AspNetCore

ASP.NET Core Extensions for DevAttic Hive

FinTech.Licensing

FinTech Alternative Licensing

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.5 342,711 2/17/2018

v1.1.5

- republish with support netstandard1.0, netstandard1.3, netstandard2.0, PCL, and .NET Framework 4.0+