Standard.Licensing
1.1.5
See the version list below for details.
dotnet add package Standard.Licensing --version 1.1.5
NuGet\Install-Package Standard.Licensing -Version 1.1.5
<PackageReference Include="Standard.Licensing" Version="1.1.5" />
paket add Standard.Licensing --version 1.1.5
#r "nuget: Standard.Licensing, 1.1.5"
// 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
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
- dnauck/Portable.Licensing for the original work.
License
This project is licensed under MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
-
.NETStandard 1.3
- NETStandard.Library (>= 1.6.1)
-
.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 (33)
Showing the top 5 NuGet packages that depend on Standard.Licensing:
Package | Downloads |
---|---|
FenixAlliance.ACL.Dependencies
Application Component for the Alliance Business Suite. |
|
uMarketingSuite.Core
The all-in-one marketing solution for the Umbraco CMS - assemblies only |
|
Monotype.Core
This is the core library for monotype web publishing tool, please use Monotype package instead. |
|
TrustImage.TiibSigner
Trustimage.TiibSigner é um pacote para assinatura de documento pdf com certificado digital. |
|
RemoteFramework.Core
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.1.5
- republish with support netstandard1.0, netstandard1.3, netstandard2.0, PCL, and .NET Framework 4.0+