USB License Dongles


USB license dongles have long been a reliable method for securing and managing software licenses within the software industry. These specialized USB sticks function as tangible hardware keys, authenticating software applications and preventing unauthorized use.

The LICENSE4J licensing library significantly enhances this concept by offering exceptional flexibility: it allows developers to utilize virtually any brand or model of standard USB stick as a license dongle. This liberates developers from reliance on proprietary dongles, providing the freedom to select from a vast array of readily available USB devices.

The LICENSE4J library operates by intelligently detecting key identifiers from the connected USB stick, including its vendor ID, product ID, and serial number. This capability enables seamless integration of the chosen USB device into the software licensing workflow, ensuring that only users possessing the correct, authenticated dongle can access the software. See an example on how to get USB details and use as a license dongle at github

Implementing this system is remarkably straightforward. Developers simply create an empty file on the designated USB stick, which serves as a marker for the license validation process. Concurrently, they must define the corresponding vendor and product IDs within their software during the license validation stage. This streamlined activation process not only enhances security by tying software access to a physical key but also simplifies deployment for both developers and end-users. Crucially, no third-party software is required for the detection of USB stick properties; the LICENSE4J library inherently provides the necessary vendor ID and product ID for the validation process.

License.getInstance().getBuilder()
    .product("product-hash-value")
    // null vendor, product id, put an empty file named "license.lic" in the root folder
    .usbDongle(null, null, "license.lic")
    .build();

System.out.println("name        :" + License.getInstance().getSystemInformation().getUSBDongleName());
System.out.println("vendor Id   :" + License.getInstance().getSystemInformation().getUSBDongleVendorId());
System.out.println("product Id  :" + License.getInstance().getSystemInformation().getUSBDongleProductId());
System.out.println("serial      :" + License.getInstance().getSystemInformation().getUSBDongleSerial());


To configure your software for USB dongle licensing, you must invoke the usbDongle method within the builder class. Concurrently, you need to define a specific license file name or path that the system will search for on the detected USB stick or pen drive. This ensures that the license data is correctly associated with and located on the physical dongle for validation purposes.

String myUSBVendorId = "0951"; // Kingston
String myUSBProductId = "1625"; // DataTraveler

License.getInstance().getBuilder()
        .product("product-hash-value")
        .usbDongle(myUSBVendorId, myUSBProductId, "license.lic")
        .build();

License.getInstance().validate("the license key");


The Licensing library intelligently recognizes a USB stick as a valid license dongle when it contains a file at the specified path and possesses matching vendor ID and product ID (if provided). A critical security feature of this system is its reliance on the USB device's unique serial number. If the license file is copied from one USB stick to another, even if the new stick shares the same vendor ID and product ID, the license will become invalid because the serial numbers will not match. This ensures that the license remains bound to the original physical dongle.

While both the Vendor ID and Product ID are optional parameters, it's highly recommended to include at least the Vendor ID. Doing so restricts the use of your USB dongle licenses to USB devices from specific, trusted manufacturers, thereby enhancing the overall security and reliability of your licensing scheme.

A straightforward example application demonstrating how to detect a USB dongle and write a license file to it is available in the github repository.