Skip to content

Software License Dongle for MATLAB and Simulink

If you sell a MATLAB toolbox, a Simulink library or a model-based product, the thing you are protecting is usually not code at all. It is the plant model, the controller gains, the calibration set or the coefficient tables — the part that took years of measurement to get right and that a competitor cannot reproduce from your documentation.

That makes MATLAB unusually well suited to doing licensing properly, because the valuable data is already separate from the code.

The Binding

File Exchange version badge

addpath('<SDK>/bindings/matlab');
keynub.build();                          % once per platform: compiles the MEX gateway

ctx     = keynub.Context();
dongle  = ctx.open();                    % first dongle, or pass a serial
dongle.verifyGenuine();                  % errors unless genuine

session = dongle.openSession();
coefficients = session.appDecrypt(encryptedBlob);
session.close();Code language: Matlab (matlab)

Gate on the Parameters, Not on a Flag

Encrypt the plant coefficients with appEncrypt when you build the product, ship them encrypted, and decrypt them at model initialisation. Remove the dongle and the model does not run in a degraded mode — it has no parameters to run with. The SDK includes a sample that does exactly this on real plant coefficients, and one that builds a dongle-gated Simulink model in code (so there is no binary .slx to version).

MATLAB Coder and Simulink Coder

This is where most licensing schemes fall over. Generated C does not run inside MATLAB, so a MEX-based binding cannot come along — and that generated C is often the thing you ship. The SDK includes a small shim that links the licence check into MATLAB Coder and Simulink Coder output, so the protection survives code generation instead of being left behind in the development environment.

Testing Without a Dongle

bindings/matlab/tests/standin_test.m exercises every call of the +keynub classes against a stand-in for the C library compiled into the gateway, so it runs in MATLAB and in GNU Octave with no dongle and no native library. The +keynub classes are thin, so there is as little logic as possible between your code and the C ABI.

Shipping the Gateway with a MATLAB or Simulink Application

The binding is a MEX gateway, licd_mex, built against the SDK’s static library, so it is one self-contained file per platform; nothing else has to be on PATH at every start. The classes keynub.Context, keynub.Dongle and keynub.Session sit on top of it, and the Simulink block keynub.LicenseCheck is a matlab.System object.

A MATLAB Compiler standalone or web app deploys with the gateway added through mcc -a, and MATLAB Coder output calls the C API directly, so generated code carries no MATLAB dependency for the check. Under GNU Octave the gateway is built with mkoctfile against the shared library, which must then be findable at run time. On Linux, install the udev rule from NATIVES.md once, so that ordinary users may open the device.

Questions MATLAB Developers Ask

Which MATLAB Versions Does the Binding Support?

MATLAB R2016b and later, with no toolbox required for the MATLAB API; Simulink for the block and MATLAB Coder for the code-generation path. It also runs under GNU Octave.

Can a MATLAB Compiler Application Be Protected with a Dongle?

Yes, and that is where the check belongs: a compiled application ships to customers as a whole. Gate on parameters the model needs, decrypted through the dongle, rather than on a flag a patched executable can flip.

Does a MATLAB 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 MATLAB 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.

Can Several Dongles Be Connected at Once?

Yes. The SDK enumerates every attached dongle with its serial number and device path, and you open one by serial; with no serial given, the first dongle found is used.

Can a License Written from MATLAB 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: matlab/verify_and_read.m, simulink/keynub_license_gate.m, matlab/codegen. Binding source: bindings/matlab. 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