License dongles have been a staple in the software industry for many years, serving as a method of securing
and managing software licenses. These dongles are typically specialized USB sticks, designed to work as
hardware keys that authenticate the legitimacy of software applications.
One versatile solution in this realm is the License4J licensing library, which distinguishes itself by
allowing the use of any brand or model of USB stick as a USB license dongle. This flexibility means that
developers are not restricted to proprietary dongles, granting them the freedom to choose from a wide range
of USB devices.
The License4J library operates by detecting essential identifiers from the USB stick, including the vendor
ID, product ID, and serial number. This capability enables the seamless integration of the USB stick into
the software licensing process, ensuring that only authorized users can access the software.
To implement this system, developers simply need to create an empty file on the USB stick, which acts as a
marker for the license validation process. Along with this, they must define the vendor and product IDs in
their software during the licensing validation stage. This straightforward approach not only streamlines the
activation process but also enhances the security of the software, making it accessible solely to those who
possess the correct USB license dongle.
No third-party software is needed to detect USB stick properties. The Licensing library provides the 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());
Define a license file in the builder and use properties to begin. Once the license is validated, the license
data will be saved in the specified license file.
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 will recognize the USB stick that contains a file in a specified path, along with the
matching vendor ID and product ID. This will allow it to function as a USB license dongle. If someone copies
the license file from one USB stick to another (even if the new stick has the same vendor ID and product
ID), the license will become invalid because the serial numbers will not match.
While both Vendor ID and Product ID are optional, it is recommended to include at least the Vendor ID to
restrict USB dongle usage to known, reliable brands.