All Projects → Cryptolens → cryptolens-java

Cryptolens / cryptolens-java

Licence: MIT license
Client API to access the functionality of Cryptolens Web API

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to cryptolens-java

netlicensing.io
Labs64 NetLicensing - Innovative License Management Solution
Stars: ✭ 13 (-45.83%)
Mutual labels:  licensing, licensing-as-a-service, offline-licensing, licensing-library
cryptolens-dotnet
Client API to access the functionality of Cryptolens Web API
Stars: ✭ 17 (-29.17%)
Mutual labels:  license-checking, licensing-as-a-service, offline-licensing, licensing-library
cryptolens-python
Cryptolens Client API for Python
Stars: ✭ 107 (+345.83%)
Mutual labels:  license-checking, licensing-as-a-service, offline-licensing, licensing-library
cryptolens-cpp
C++ Interface for Cryptolens Web API
Stars: ✭ 15 (-37.5%)
Mutual labels:  license-checking, licensing-as-a-service, licensing-library
sandia-public-license
This is not a license of honor. No highly esteemed copyright statement is written here.
Stars: ✭ 114 (+375%)
Mutual labels:  licensing
Npm License Crawler
Analyzes license information for multiple node.js modules (package.json files) as part of your software project.
Stars: ✭ 168 (+600%)
Mutual labels:  licensing
Pelock Software Protection And Licensing Sdk
Software copy protection against cracking & reverse engineering with anti-cracking & anti-debugging techniques. Software license key system with time trial options.
Stars: ✭ 109 (+354.17%)
Mutual labels:  licensing
Ethicalsource.dev
Home of the Organization for Ethical Source
Stars: ✭ 105 (+337.5%)
Mutual labels:  licensing
veye-checker
This projects creates SHA values for locale binaries - Shazam for packages.
Stars: ✭ 22 (-8.33%)
Mutual labels:  licensing
TrialMaker.Demo
A powerful yet straight-forward library suite that provides secure trial license generation and copy-protection features for .NET applications. It also supports premium license generation for expired free-trials.
Stars: ✭ 21 (-12.5%)
Mutual labels:  licensing
license-ls
Get a list of licenses used by a projects dependencies
Stars: ✭ 17 (-29.17%)
Mutual labels:  license-checking
License List Data
Various data formats for the SPDX License List including RDFa, HTML, Text, and JSON
Stars: ✭ 182 (+658.33%)
Mutual labels:  licensing
secureapp
Secure licensing solution for .NET
Stars: ✭ 13 (-45.83%)
Mutual labels:  licensing
Cargo About
📜 Cargo plugin to generate list of all licenses for a crate 🦀
Stars: ✭ 148 (+516.67%)
Mutual labels:  licensing
simpleopendata
simple guidelines for publishing open data in useful formats
Stars: ✭ 87 (+262.5%)
Mutual labels:  licensing
Licensingviewcontroller
📃 UIViewController subclass with a simple API for displaying licensing information.
Stars: ✭ 107 (+345.83%)
Mutual labels:  licensing
Standard.licensing
Easy-to-use licensing library for .NET Framework, Mono, .NET Core, and Xamarin products
Stars: ✭ 239 (+895.83%)
Mutual labels:  licensing
license-compatibility
©️ Check compatibility between different SPDX licenses
Stars: ✭ 31 (+29.17%)
Mutual labels:  licensing
Choosealicense.com
A site to provide non-judgmental guidance on choosing a license for your open source project
Stars: ✭ 2,648 (+10933.33%)
Mutual labels:  licensing
Askalono
A tool & library to detect open source licenses from texts
Stars: ✭ 201 (+737.5%)
Mutual labels:  licensing

Cryptolens Licensing for Java

This repository contains examples of how to verify license keys in Java applications.

This library is continuously being improved. Please contact us at [email protected] should you have any questions.

Javadoc can be found here: https://help.cryptolens.io/api/java/

Adding the library

There are two pre-compiled jar files: cryptolens.jar and cryptolens-android.jar. If your application is cross platform or if you would like to have as few dependencies as possible (e.g., without slf4j), we recommend to use cryptolens-android.jar instead.

If you choose to use cryptolens-android.jar, GetMachineCode and IsOnRightMachine need to be called with the version parameter set to 2. For example, Helpers.GetMachineCode(2) or Helpers.IsOnRightMachine(license, 2). 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 the cryptolens.jar file, the code below should generate successful result. A working project with the code below can be found in the example-app folder.

import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public class Main {

    public static void main(String[] args) {
        String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
        String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";

        LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()));

        if (license == null || !Helpers.IsOnRightMachine(license)) {
            System.out.println("The license does not work.");
        } else {
            System.out.println("The license is valid!");
            System.out.println("It will expire: " + license.Expires);
        }
    }
}

In order to adjust this code to your products, several parameters needs to be changed, which we outline below:

  • 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.

String licenseString = license.SaveAsString();

When loading it back, we can use the code below:

LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString);

If you want to make sure that the license file is not too old, you can specify the maximum number of days as shown below (after 30 days, this method will return null).

LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString, 30);

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 the ActivateModel. 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.

import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public static void main(String args[]) {
    String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
    String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";

    LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(), 300, 1));
    if (license == null || !Helpers.IsOnRightMachine(license, true, true)) {
        System.out.println("The license does not work.");
    } else {
        System.out.println("The license is valid!");
        System.out.println("It will expire: " + license.Expires);
    }
}

Deactivation

In order to deactivate a license, we can call the Key.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).

import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public static void main(String args[]) {
    String auth = "";

    boolean result = Key.Deactivate(auth, new DeactivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode()));
    if (result == true) {
        System.out.println("Deactivation successful.");
    } else {
        System.out.println("Deactivation failed.");
    }
}

The call above is useful when node-locking is used. If it's a floating license, deactivation is not necessary since licenses will be deactivated automatically after a certain period of time. However, to force a deactivation earlier, you can use similar code as above with addition of a boolean flag.

import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public static void main(String args[]) {
    String auth = "";

    boolean result = Key.Deactivate(auth, new DeactivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(), true));
    if (result == true) {
        System.out.println("Deactivation successful.");
    } else {
        System.out.println("Deactivation failed.");
    }
}

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 using LicenseServerUrl 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:

GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080";

We do this because there is currently no overload method that accepts LicenseServerUrl parameter.

The entire code is shown below:

String RSAPubKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTn+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==<Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

String auth = APIKey.get("getkeyactivate");

APIError error = new APIError();

GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080";

LicenseKey license = Key.GetKey(auth, RSAPubKey, model , error);

if (license == null) {
    System.out.println("The license does not work.");
    System.out.println("Error: " + error.message);
} else {
    System.out.println("The license is valid!");
    System.out.println("It will expire: " + license.Expires);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].