Skip to content

Software License Dongle for C# .NET

The .NET binding is a single NuGet package that carries the native library for you, so there is no “copy this DLL next to your executable” step and no architecture guessing.

NuGet version badge

dotnet add package KeyNub.LicenseDongleCode language: Bash (bash)

Reading a license

using KeyNub.LicenseDongle;

using var ctx = LicenseDongleContext.Create();
using var dongle = ctx.Open();               // first dongle, or pass a serial
dongle.VerifyGenuine();                      // throws unless genuine

using var session = dongle.OpenSession();
byte[] license = session.ReadRecord("license");Code language: C# (cs)

Dongle is IDisposable, so a using declaration closes the device on every exit path, including exceptions. That matters more than it sounds: the driver keeps a small fixed table of open handles, and a leaked one is a support call three weeks later.

C#, VB.NET and F# share one assembly

There is no separate VB binding. KeyNub.LicenseDongle is a .NET assembly, so Visual Basic and F# consume exactly the same API. We ship a VB.NET sample anyway, because the call style differs enough to be worth showing — Using blocks, no var, and Option Strict On, which is what you want for interop.

Do not gate on a boolean

An if (licensed) is one IL instruction away from if (true), and .NET assemblies are especially easy to inspect and rewrite — a decompiler will hand someone a readable copy of your check. Obfuscation slows that down; it does not stop it. Make the program need something the dongle produces instead:

// Weak: a branch a patcher removes.
if (isLicensed) EnableFeature();

// Strong: the values only exist when the dongle does.
byte[] coefficients = session.AppDecrypt(EncryptedBlobFromInstaller);Code language: C# (cs)

Because the decrypted data is an input rather than a permission, removing the check does not unlock the feature — it removes the feature’s data.

Code

Runnable sample: csharp/verify_and_read. Binding source: bindings/dotnet. Both are Apache-2.0, in the public SDK repository; the prebuilt native libraries are in the repository’s natives/ folder, one per platform.

All supported languages · All industries · Buy a KeyNub · Ask us something