Zentitle2Core Library

The .NET Licensing Client implements bindings to the Zentitle2Core C++ library's methods, allowing .NET applications to leverage the functionality of the C++ Core library using the C# code.

Zentitle2Core Library Integration

  1. Download the zip package with the Zentitle2Core binaries from the Zentitle2Core's Release Notes page.

  2. Extract the content from the downloaded zip package. Depending on your needs and preferences, you can place the platform-specific binaries in the root directory of your project and ensure that they are always copied to the output/publish directory or provide a custom DllImportResolver.

In the example below, the application is targeting Windows OS. Thus, only the Windows binary has been included in the project.

This solution works for all the operation systems, as .NET runtime always loads the binary depending on the OS that the application is currently running (.dll on Windows, .so on Linux and .dylib on MacOS).

The above approach has an issue when targeting MacOS with both the x86_64 and arm64 architectures. The Zentitle2Core binaries must be explicitly compiled for each architecture but have the same .dylib extension. For that reason, it's not possible to place them both in the project's root directory, and a Custom DllImportResolver must be used.

Custom DllImportResolver

For the cases when you want to target operation systems with multiple architectures or you don't want to place the Zentite2Core binaries into the project's root directory, a custom DllImportResolver can be implemented that loads the correct library depending on your project's structure. For the default Zentitle2Core release structure, the following Zentitle2CoreDllImportResolver implementation would work:

public static IntPtr Zentitle2CoreDllImportResolver(
     string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
    if (libraryName != "Zentitle2Core")
    {
        // Fallback to the default import resolver.
        return IntPtr.Zero;
    }

    if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
    {
        if (RuntimeInformation.OSArchitecture == Architecture.X64 ||
            RuntimeInformation.OSArchitecture == Architecture.X86)
        {
            return NativeLibrary
                     .Load("libZentitle2_v1.2.1/MacOS_x86_64/libZentitle2Core.dylib");
        }

        return NativeLibrary
                 .Load("libZentitle2_v1.2.1/MacOS_arm64/libZentitle2Core.dylib");
    }

    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
    {
        return NativeLibrary
                 .Load("libZentitle2_v1.2.1/Windows_x86_64/Zentitle2Core.dll");
    }

    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
        RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
    {
        return NativeLibrary
                 .Load("libZentitle2_v1.2.1/Linux_x86_64/libZentitle2Core.so");
    }

        // Otherwise, fallback to the default import resolver.
        return IntPtr.Zero;
}

The following code must be executed before the first use of the Zentitle2Core library to instruct the .NET runtime to use the custom DllImportResolver when loading the binaries.

NativeLibrary.SetDllImportResolver(
    typeof(IActivation).Assembly, Zentitle2CoreDllImportResolver);

Using Zentitle2Core Methods

After the Zentitle2Core binaries have been integrated into the .Net application, the following activation options can be used to leverage the functionality implemented in the Core library.

Device Fingerprint

A Device Fingerprint is a unique identifier of the device on which the application is being executed. Therefore, it is a good candidate for use as the activation's seat ID.

var activation = new Activation(options => 
    options.WithSeatId(Zentitle2Core.DeviceFingerprint.GenerateForCurrentMachine));

Offline Activation

The Zentitle2Core library implements the logic responsible for encrypting and decrypting the tokens exchanged in the Offline License Activation process. Without the Zentitle2Core library, this functionality cannot be used.

var activation = new Activation(options => 
    options.WithOfflineActivationSupport(off =>
       off.UseTenantRsaKeyModulus(licensingOptions.TenantRsaKeyModulus));

Secure Storage

It is not trivial to persist the activation's details into a license file that is hard to tamper and should not work on a different device (or even in a different folder within the same machine). The Zentitle2Core library implements this functionality using low-level code, making the license file encrypted and unusable when copied/moved elsewhere.

Secure storage also helps place the file into the correct system directory, depending on the OS that the application is currently running on. It provides predefined directories USER_DATA and PUBLIC_DATA. Depending on the application's licensing model, you can decide which one to use. The code below will create the ../{USER_DATA Dir}/YourAppName/.license file for your app.

var activation = new Activation(options => 
    options.UseStorage(
        Zentitle2Core.SecureActivationStorage
           .WithAppDirectory(PredefinedSystemFolder.UserData, "YourAppName")));

Last updated

Zentitle2

Service terms

© Copyright - Nalpeiron, all rights reserved Website use subject to Terms and Conditions. See our Privacy Policy Use of Zentitle is subject to our Service Terms and Conditions