Adding the library
This library can be installed using Maven Central, for more information, please refer to this page. If you do not want to use Maven, you can use the jar file attached to the latest release. If you plan to run the library on other platforms, it is possible to use the library withoutoshi-core
. If you choose to skip the oshi-core
dependency, GetMachineCode
and IsOnRightMachine
need to be called with the version parameter set to 3. For example, Helpers.GetMachineCode(3)
or Helpers.IsOnRightMachine(license, 3)
. If your application will run on an Android device, we recommend to use a different way to obtain the machine code, which is described here.
Example
Key verification
The following example is similar to what is covered in the key verification tutorial. Assuming you have referenced thecryptolens.jar
file, the code below should generate successful result. A working project with the code below can be found in the example-app folder.
RSAPubKey
- the RSA Public key, which can be found on this page.auth
- the access token (can be found here, in API Keys section).product_id
- the id of the product can be found on the product page (in the example above, it’s 3646).key
- the license key to be verified (above it’s MPDWY-PQAOW-FKSCH-SGAAU).machine_code
- the unique id of the device, which may require root access. Note, this value is not the same as the one generated by the .NET client.
Note: The code above assumes that node-locking is enabled. By default, license keys created with Maximum Number of Machines set to zero, which deactivates node-locking. As a result, machines will not be registered and the call to Helpers.IsOnRightMachine(license) will return False. You can read more about this behaviour here. For testing purposes, please feel free to remove Helpers.IsOnRightMachine(license) from the if statement.
Offline activation (saving/loading licenses)
Assuming the license key verification was successful, we can save the result in a file so that we can use it instead of contacting Cryptolens.Note:
LicenseKey.LoadFromString
does not check the ProductId. In case you have multiple products, we recommend that you check that the ProductId corresponds to the product where the user tries to use the license file.Floating licenses
Floating licenses can be enabled by passing a floatingTimeInterval to theActivateModel
. Optionally, you can also allow customers to exceed the bound by specifying the maxOverdraft.
The code below has a floatingTimeInterval of 300 seconds and maxOverdraft set to 1. To support floating licenses with overdraft, the call to Helpers.IsOnRightMachine(license, true, true)
needs two boolean flags to be set to true.
Deactivation
In order to deactivate a license, we can call theKey.Deactivate
method, as shown below. Note, we need an access token with Deactivate permission, so the ones used in earlier examples cannot be used (unless they have this permission).
Calling through the license server
If you would like to re-route the requests through our license-server that is installed on the client site, you can specify its url usingLicenseServerUrl
parameter. All API models expose this parameter.
For example, let’s suppose that your client runs the license server on http://10.1.1.6:8080
and you want to call Key.GetKey()
. In this case, we first define all parameters for the request and then modify the license server url:
LicenseServerUrl
parameter.
The entire code is shown below: