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. 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 — 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.

Shipping the Native Library with a C# Application

The KeyNub.LicenseDongle NuGet package carries the native library for every platform under runtimes/<rid>/native/: win-x86, win-x64, win-arm64, linux-x64, linux-arm64 and osx. On .NET 8 and later the host picks the right one at run time, and a framework-dependent or self-contained dotnet publish for a runtime identifier takes exactly that one. On .NET Framework, through netstandard2.0, the package’s MSBuild targets copy the library next to your executable and the binding pre-loads it.

Nothing else is deployed: no driver, no service, no registry entry. Single-file publishing and trimming work, because the native library is a plain file beside the executable rather than something the linker sees. On Linux, install the udev rule from NATIVES.md once, so that ordinary users may open the device.

Questions C# Developers Ask

Which .NET Versions Does the Binding Support?

The assembly targets net8.0 and netstandard2.0, so it runs on .NET 8 and later and on .NET Framework 4.6.1 and later, on Windows, Linux and macOS.

Does a C# Application Need Administrator Rights to Talk to the Dongle?

No, and no driver either: the dongle is a USB HID device that the operating systems handle with their built-in class drivers. On Linux, install the shipped udev rule once so that ordinary users may open it; without the rule the SDK reports access denied and names the cause in its error detail.

Does a C# License Check Need an Internet Connection?

No. Verification is a local exchange between your program and the dongle over USB: the SDK checks the dongle’s certificate chain to KeyNub’s root and runs a live challenge-response. There is no activation server and no account, so the check works on air-gapped machines.

Who Can Read the License Records on a Dongle?

Anyone holding the dongle: a program opens a session and reads records, and can decrypt data sealed for that dongle. Writing records, erasing them and incrementing counters need your write key. What the dongle guarantees is that none of it is available without the dongle present.

Can a License Written from C# Be Read by a Program in Another Language?

Yes. Every binding drives the same core library and the same dongle, and records and sealed data are language-neutral bytes. Your issuing tool can be written in one language and your product in another.

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