VOOZH about

URL: https://www.nuget.org/packages/Ecng.Licensing/

⇱ NuGet Gallery | Ecng.Licensing 1.0.74




👁 Image
Ecng.Licensing 1.0.74

dotnet add package Ecng.Licensing --version 1.0.74
 
 
NuGet\Install-Package Ecng.Licensing -Version 1.0.74
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ecng.Licensing" Version="1.0.74" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Licensing" Version="1.0.74" />
 
Directory.Packages.props
<PackageReference Include="Ecng.Licensing" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ecng.Licensing --version 1.0.74
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Ecng.Licensing, 1.0.74"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ecng.Licensing@1.0.74
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ecng.Licensing&version=1.0.74
 
Install as a Cake Addin
#tool nuget:?package=Ecng.Licensing&version=1.0.74
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Ecng.Licensing

A lightweight licensing library for .NET applications supporting license validation, expiration management, and multi-platform licensing.

Purpose

Ecng.Licensing provides a simple and flexible licensing system for commercial .NET applications. It handles license parsing, validation, feature management, and expiration policies across multiple platforms (Windows, Linux, macOS).

Key Features

  • XML-based license format with digital signatures
  • Multi-platform license support (Windows, Linux, macOS)
  • Feature-based licensing with granular control
  • Hardware ID binding for license protection
  • License expiration management with configurable actions
  • Account-based licensing
  • Support for both file-based and byte-array license loading

Installation

Add a reference to the Ecng.Licensing package in your project.

Core Concepts

License Structure

A license contains:

  • License ID: Unique identifier for the license
  • Issued To: Email or name of the licensee
  • Issued Date: When the license was created
  • Features: Platform-specific features with expiration dates
  • Signature: Digital signature for validation

License Features

Each feature has:

  • Name: Feature identifier (e.g., "Trading", "Analytics")
  • Expiration Date: When the feature expires
  • Expire Action: What happens when the feature expires (PreventWork or PreventUpgrade)
  • Hardware ID: Optional hardware binding
  • Account: Optional account identifier
  • OneApp ID: Optional single-application binding

Usage Examples

Loading a License from File

using Ecng.Licensing;
using System.IO;

// Load license from file
byte[] licenseData = File.ReadAllBytes("license.lic");
var license = new License("license.lic", licenseData);

Console.WriteLine($"License ID: {license.Id}");
Console.WriteLine($"Issued To: {license.IssuedTo}");
Console.WriteLine($"Issued Date: {license.IssuedDate}");

Loading a License from Byte Array

using Ecng.Licensing;

// Load license from embedded resource or byte array
byte[] licenseBytes = GetLicenseFromResource();
var license = new License(licenseBytes);

Accessing License Features

using Ecng.Licensing;
using System.Runtime.InteropServices;

// Get features for the current platform
var currentPlatform = OSPlatform.Windows; // or OSPlatform.Linux, OSPlatform.OSX

if (license.Features.TryGetValue(currentPlatform, out var features))
{
 foreach (var feature in features)
 {
 Console.WriteLine($"Feature: {feature.Name}");
 Console.WriteLine($"Expires: {feature.ExpirationDate}");
 Console.WriteLine($"Action on expire: {feature.ExpireAction}");

 if (!string.IsNullOrEmpty(feature.HardwareId))
 Console.WriteLine($"Hardware ID: {feature.HardwareId}");

 if (!string.IsNullOrEmpty(feature.Account))
 Console.WriteLine($"Account: {feature.Account}");
 }
}

Checking Feature Availability

using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;

public bool IsFeatureAvailable(License license, string featureName)
{
 var currentPlatform = OSPlatform.Windows;

 if (!license.Features.TryGetValue(currentPlatform, out var features))
 return false;

 var feature = features.FirstOrDefault(f => f.Name == featureName);

 if (feature == null)
 return false;

 // Check if feature has expired
 if (DateTime.UtcNow > feature.ExpirationDate)
 {
 if (feature.ExpireAction == LicenseExpireActions.PreventWork)
 return false;
 }

 return true;
}

// Usage
if (IsFeatureAvailable(license, "Trading"))
{
 Console.WriteLine("Trading feature is available");
}

Validating Hardware ID

using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;

public bool ValidateHardwareId(License license, string currentHardwareId)
{
 var currentPlatform = OSPlatform.Windows;

 if (!license.Features.TryGetValue(currentPlatform, out var features))
 return false;

 // If any feature has a hardware ID, validate it
 var featuresWithHwId = features.Where(f => !string.IsNullOrEmpty(f.HardwareId));

 if (!featuresWithHwId.Any())
 return true; // No hardware binding

 return featuresWithHwId.Any(f => f.HardwareId.Equals(currentHardwareId,
 StringComparison.OrdinalIgnoreCase));
}

Checking License Expiration

using Ecng.Licensing;
using System.Linq;

public class LicenseStatus
{
 public bool IsValid { get; set; }
 public bool IsExpired { get; set; }
 public DateTime? ExpirationDate { get; set; }
 public LicenseExpireActions? ExpireAction { get; set; }
}

public LicenseStatus GetLicenseStatus(License license, string featureName)
{
 var currentPlatform = System.Runtime.InteropServices.OSPlatform.Windows;
 var status = new LicenseStatus { IsValid = false };

 if (!license.Features.TryGetValue(currentPlatform, out var features))
 return status;

 var feature = features.FirstOrDefault(f => f.Name == featureName);
 if (feature == null)
 return status;

 status.ExpirationDate = feature.ExpirationDate;
 status.ExpireAction = feature.ExpireAction;
 status.IsExpired = DateTime.UtcNow > feature.ExpirationDate;
 status.IsValid = !status.IsExpired ||
 feature.ExpireAction == LicenseExpireActions.PreventUpgrade;

 return status;
}

// Usage
var status = GetLicenseStatus(license, "Analytics");
if (status.IsExpired)
{
 Console.WriteLine($"License expired on {status.ExpirationDate}");
 Console.WriteLine($"Action: {status.ExpireAction}");
}

Working with Multiple Features

using Ecng.Licensing;
using System.Linq;
using System.Runtime.InteropServices;

public class LicenseManager
{
 private readonly License _license;
 private readonly OSPlatform _platform;

 public LicenseManager(License license)
 {
 _license = license;
 _platform = GetCurrentPlatform();
 }

 private OSPlatform GetCurrentPlatform()
 {
 if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
 return OSPlatform.Windows;
 if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
 return OSPlatform.Linux;
 if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
 return OSPlatform.OSX;

 throw new PlatformNotSupportedException();
 }

 public bool HasFeature(string featureName)
 {
 if (!_license.Features.TryGetValue(_platform, out var features))
 return false;

 return features.Any(f => f.Name.Equals(featureName,
 StringComparison.OrdinalIgnoreCase));
 }

 public IEnumerable<string> GetActiveFeatures()
 {
 if (!_license.Features.TryGetValue(_platform, out var features))
 return Enumerable.Empty<string>();

 return features
 .Where(f => DateTime.UtcNow <= f.ExpirationDate ||
 f.ExpireAction == LicenseExpireActions.PreventUpgrade)
 .Select(f => f.Name);
 }

 public IEnumerable<LicenseFeature> GetExpiringFeatures(int daysAhead)
 {
 if (!_license.Features.TryGetValue(_platform, out var features))
 return Enumerable.Empty<LicenseFeature>();

 var threshold = DateTime.UtcNow.AddDays(daysAhead);

 return features.Where(f =>
 f.ExpirationDate > DateTime.UtcNow &&
 f.ExpirationDate <= threshold);
 }
}

// Usage
var manager = new LicenseManager(license);

// Check if feature exists
if (manager.HasFeature("Trading"))
{
 Console.WriteLine("Trading feature is licensed");
}

// Get all active features
foreach (var feature in manager.GetActiveFeatures())
{
 Console.WriteLine($"Active feature: {feature}");
}

// Get features expiring in next 30 days
foreach (var feature in manager.GetExpiringFeatures(30))
{
 Console.WriteLine($"Feature {feature.Name} expires on {feature.ExpirationDate}");
}

Accessing License Properties

using Ecng.Licensing;

// Access basic license information
Console.WriteLine($"License Version: {license.Version}");
Console.WriteLine($"License ID: {license.Id}");
Console.WriteLine($"Issued To: {license.IssuedTo}");
Console.WriteLine($"Issued Date: {license.IssuedDate:yyyy-MM-dd}");

// Access raw license data
byte[] originalBody = license.Body;
byte[] bodyWithoutSignature = license.BodyWithoutSignature;
byte[] signature = license.Signature;

// Get string representation
string licenseInfo = license.ToString(); // Returns "N{Id} ({HardwareId})"

License Expire Actions

The LicenseExpireActions enum defines what happens when a license expires:

  • PreventWork: The feature becomes completely unavailable after expiration
  • PreventUpgrade: The feature continues to work but cannot be upgraded to newer versions
using Ecng.Licensing;

public void HandleExpiration(LicenseFeature feature)
{
 switch (feature.ExpireAction)
 {
 case LicenseExpireActions.PreventWork:
 Console.WriteLine("Feature will stop working after expiration");
 // Disable feature completely
 break;

 case LicenseExpireActions.PreventUpgrade:
 Console.WriteLine("Feature will continue working but no updates allowed");
 // Allow current version usage only
 break;
 }
}

Best Practices

  1. Validate Licenses Early: Check license validity during application startup
  2. Handle Expiration Gracefully: Show warnings before license expiration
  3. Secure License Storage: Store license files securely and validate signatures
  4. Hardware Binding: Use hardware IDs for additional security when needed
  5. Multi-Platform Support: Check platform-specific features appropriately
  6. Regular Validation: Periodically re-validate licenses during application runtime

Platform Support

  • .NET Standard 2.0+
  • .NET 6.0+
  • .NET 10.0+

Supports Windows, Linux, and macOS platforms.

Dependencies

  • Ecng.Common
  • Ecng.Collections
  • Ecng.Localization

License Format

Licenses are stored in XML format with the following structure:

<license>
 <ver>1.0</ver>
 <id>12345</id>
 <issuedTo>user@example.com</issuedTo>
 <issuedDate>20240101 00:00:00</issuedDate>
 <platforms>
 <platform name="Windows">
 <feature name="Trading" expire="20251231 23:59:59" expireAction="PreventWork" hardwareId="" account="" />
 <feature name="Analytics" expire="20251231 23:59:59" expireAction="PreventUpgrade" hardwareId="" account="" />
 </platform>
 </platforms>
 <signature>BASE64_SIGNATURE</signature>
</license>

See Also

  • - Common utilities and extensions
  • - Collection utilities
  • - Localization support
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Ecng.Licensing:

Package Downloads
StockSharp.Licensing

Licensing components. More info on web site https://stocksharp.com/store/

StockSharp.Web.DomainModel

StockSharp WebApi

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.74 52 6/17/2026
1.0.73 97 6/12/2026
1.0.72 201 5/15/2026
1.0.71 93 5/14/2026
1.0.70 103 5/3/2026
1.0.69 136 4/14/2026
1.0.68 132 3/17/2026
1.0.67 119 3/17/2026
1.0.66 116 3/15/2026
1.0.65 845 3/3/2026
1.0.64 114 2/28/2026
1.0.63 513 2/10/2026
1.0.62 378 2/4/2026
1.0.61 344 2/1/2026
1.0.60 116 1/26/2026
1.0.59 114 1/22/2026
1.0.58 120 1/19/2026
1.0.57 119 1/19/2026
1.0.56 127 1/18/2026
1.0.55 121 1/18/2026
Loading failed