Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Client for the KeyNub USB license dongle: genuineness check, license records, hardware counters, dongle-bound encryption
Contributed by: KeyNub
Wolfram Language client for the KeyNub USB license dongle: verify that a dongle is genuine, read and write the license records it stores, use its hardware counters, and encrypt data so that only a dongle can decrypt it. Pure Wolfram Language over the SDK's flat C API through ForeignFunctionLoad, for Mathematica, Wolfram Engine and wolframscript on Windows, Linux and macOS.
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["KeyNub/KeyNubLicDongle"]
To load the code after installation, evaluate this code:
Needs["KeyNub`KeyNubLicDongle`"]
| Group | Functions |
| Library | LicDongleLibraryPath, LicDongleLibraryVersion, LicDongleStatusText, LicDongleLastErrorDetail |
| Devices | LicDongleDevices, LicDongleOpen, LicDongleOpenPath, LicDongleClose, LicDongleSerial, LicDongleInfo |
| Authenticity | LicDongleVerifyGenuine, LicDongleGenuineQ, LicDongleSetTrustRoot |
| Session | LicDongleSessionOpen, LicDongleSessionClose, LicDongleAuthorizeWrite, LicDongleRotateWriteKey |
| Records | LicDongleRecords, LicDongleReadRecord, LicDongleWriteRecord, LicDongleEraseRecord, LicDongleEraseAllRecords |
| Counters | LicDongleReadCounter, LicDongleIncrementCounter |
| Application data | LicDongleAppEncrypt, LicDongleAppDecrypt |
A dongle is an integer handle from LicDongleOpen; the library holds up to 32 open handles. LicDongleInfo gives an association with "ProtocolVersion", "FirmwareVersion", "SecureElementReady", "Provisioned", "Isolated", "WatchdogReboot", "WriteAuthRotated", "DataCapacity" and "DataFree". LicDongleVerifyGenuine gives "Genuine", "Serial" and "ProvisionedDate"; LicDongleGenuineQ is the non-failing form and gives False on every failure. Records, counters and application-data encryption need a session (LicDongleSessionOpen); writing, erasing, incrementing and key rotation need the session elevated with the dongle's write key (LicDongleAuthorizeWrite, a P-256 private key in PKCS#8 DER). Every function taking bytes accepts a ByteArray or a String (stored as UTF-8). Failures are Failure["LicDongleError", …] with "Status" (the C status code), "Operation" and "Detail". The native library keynub_licdongle_flat is part of the KeyNub SDK, not of the paclet. The paclet loads it from the path given to LicDongleLibraryPath, from the environment variable KEYNUB_LICDONGLE_FLAT_LIBRARY, from natives/ in a clone of the SDK repository (searched from the working directory upwards), or by its bare name through the operating system's library search. A kernel loads the library once; LicDongleLibraryPath[] tells which one.
If the native library is not on the operating system's library path, name it first:
List the attached dongles:
Open the first dongle and verify that it is genuine:
Gate on authenticity without handling a Failure; every failure gives False:
Read the device information:
Open a session and read the license record:
Close the session and release the dongle:
Open a dongle by serial or by device path:
Records take a ByteArray or a String; writing needs the write role:

Erase one record:
Read and increment a hardware counter; the increment gives the new value:
Encrypt data so that only a dongle can decrypt it. "Developer" lets any dongle issued to the same developer decrypt; "Device" binds the data to this dongle:
Replace the dongle's write key with your own; the shipped key is keys/keynub-shipping-writeauth.key.der in the SDK repository:
Failures carry the status code, the operation and the library's detail:
Name the native library and report which one is loaded:
Wolfram Language Version 13.1