### Android Integration Example
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Demonstrates how to integrate Cryptolens licensing into an Android application, ensuring network calls are made on a background thread and using a custom machine identifier.
```APIDOC
## Android Integration
### Description
On Android, network calls must run on a background thread to avoid `NetworkOnMainThreadException`. This example shows how to obtain a machine identifier and activate a license key within a background thread.
### Setup
Add the internet permission to your `AndroidManifest.xml`:
```xml
```
### Method
```java
// In an Activity or ViewModel
Thread thread = new Thread(() -> {
String mid = Helpers.SHA256(
android.provider.Settings.Secure.getString(
getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID));
LicenseKey license = Key.Activate(auth, RSAPubKey,
new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", mid));
runOnUiThread(() -> {
if (license == null || !Helpers.IsOnRightMachine(license, mid)) {
statusText.setText("License invalid.");
} else {
statusText.setText("License valid! Expires: " + license.Expires);
}
});
});
thread.start();
```
### Parameters
* **auth** (String) - Your application's authorization token.
* **RSAPubKey** (String) - The RSA public key for signature verification.
* **ActivateModel** - Model for activation request:
* **productId** (int) - The ID of the product.
* **licenseKey** (String) - The license key to activate.
* **machineCode** (String) - A unique identifier for the machine.
### Response
* **LicenseKey** - An object containing license details if activation is successful.
* **Expires** (String) - The expiration date of the license.
### Error Handling
If the license is invalid or the machine code does not match, an appropriate message is displayed.
```
--------------------------------
### Call API via Local License Server
Source: https://github.com/cryptolens/cryptolens-java/blob/master/README.md
Routes API requests through a locally installed license server by specifying its URL. This example demonstrates setting the `LicenseServerUrl` parameter for the `Key.GetKey` method.
```java
GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080";
```
```java
String RSAPubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTn+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==AQAB";
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);
}
```
--------------------------------
### Create Trial Key - Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Generates a time-limited trial key for the current machine. If a trial key already exists, the existing one is returned. Requires specific product flags on the Cryptolens portal.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIxMjM0IiwidHJpYWxfdG9rZW4iXQ==";
APIError error = new APIError();
CreateKeyResult result = Key.CreateTrialKey(auth, new CreateTrialKeyModel(3349, Helpers.GetMachineCode(2)), error);
if (result == null || result.result == 1) {
System.out.println("Could not create trial: " + error.message);
} else {
System.out.println("Trial key: " + result.key);
// Expected: Trial key: TRIAL-XXXX-YYYY-ZZZZ
}
```
--------------------------------
### Activate License Key in Java
Source: https://github.com/cryptolens/cryptolens-java/blob/master/README.md
Activates a license key using product ID, license key, and machine code. Ensure node-locking is configured if `IsOnRightMachine` is used. The RSA public key and authentication token are required.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
public class Main {
public static void main(String[] args) {
String RSAPubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==AQAB";
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode(2)));
if (license == null || !Helpers.IsOnRightMachine(license, 2)) {
System.out.println("The license does not work.");
} else {
System.out.println("The license is valid!");
System.out.println("It will expire: " + license.Expires);
}
}
}
```
--------------------------------
### List All Products with ProductMethods.GetProducts
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Retrieves all products associated with the account. Useful for multi-product applications to dynamically look up product IDs at runtime.
```java
import io.cryptolens.methods.ProductMethods;
import io.cryptolens.models.GetProductsResult;
import io.cryptolens.models.Product;
String prodAuth = "WyIxMjM0IiwiZ2V0cHJvZHVjdHNfdG9rZW4iXQ==";
GetProductsResult result = ProductMethods.GetProducts(prodAuth);
if (result != null && result.products != null) {
for (Product p : result.products) {
System.out.println("Product: " + p.Name + " (ID: " + p.Id + ")");
}
}
// Expected: Product: My Software (ID: 3349)
```
--------------------------------
### Key.Activate (Floating License)
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Activates a floating license, limiting concurrent activations within a rolling time window. Set `FloatingTimeInterval` (seconds) on `ActivateModel`. `MaxOverdraft` allows going beyond the seat limit. Pass `isFloatingLicense=true` (and `allowOverdraft=true` when applicable) to `IsOnRightMachine`.
```APIDOC
## Floating License Activation
### Description
Floating licenses limit concurrent activations within a rolling time window. Set `FloatingTimeInterval` (seconds) on `ActivateModel`. `MaxOverdraft` allows going beyond the seat limit. Pass `isFloatingLicense=true` (and `allowOverdraft=true` when applicable) to `IsOnRightMachine`.
### Method
```java
Key.Activate(String auth, String RSAPubKey, ActivateModel model)
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
String RSAPubKey = "...";
// floatingTimeInterval=300s, maxOverdraft=1
LicenseKey license = Key.Activate(
auth, RSAPubKey,
new ActivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(2), 300, 1)
);
if (license == null || !Helpers.IsOnRightMachine(license, 2, true, true)) {
System.out.println("Floating license check failed.");
} else {
System.out.println("Floating seat acquired. Expires: " + license.Expires);
}
// Expected: Floating seat acquired. Expires:
```
### Response
#### Success Response (200)
- **LicenseKey** (object) - The activated license key object.
#### Response Example
```json
{
"Expires": 1678886400,
"GracePeriodRemaining": 0,
"Id": 12345,
"IsFloating": true,
"MaxOverdraft": 1,
"TimeInterval": 300
}
```
```
--------------------------------
### Key.Activate — Activate a license key on a device
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Contacts the Cryptolens API to activate a license key for the current machine. On success, returns a `LicenseKey` object with the full license details; returns `null` on failure. The response is RSA-signed and the signature is verified locally. An optional `APIError` parameter captures the server's error message.
```APIDOC
## Key.Activate — Activate a license key on a device
### Description
Contacts the Cryptolens API to activate a license key for the current machine. On success, returns a `LicenseKey` object with the full license details; returns `null` on failure. The response is RSA-signed and the signature is verified locally. An optional `APIError` parameter captures the server's error message.
### Method
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String RSAPubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7...AQAB";
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
// With error reporting
APIError error = new APIError();
LicenseKey license = Key.Activate(
auth,
RSAPubKey,
new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode(2)),
error
);
if (license == null || !Helpers.IsOnRightMachine(license, 2)) {
System.out.println("License invalid. Error: " + error.message);
} else {
System.out.println("License valid! Expires: " + license.Expires);
System.out.println("Feature 1 enabled: " + license.HasFeature(1));
}
// Expected output (success): License valid! Expires: 1893456000
```
```
--------------------------------
### Attach Metadata to Licenses and Activations
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Use `Data.AddDataObject` to attach named key/value pairs to a license key or a specific machine activation. This is fundamental for usage-based licensing. Ensure the access token has the necessary permissions.
```java
import io.cryptolens.methods.Data;
import io.cryptolens.internal.BasicResult;
// Add to license key
BasicResult r1 = Data.AddDataObject(auth, license, "usage", 0, "", true); // checkForDuplicates=true
System.out.println("Added to key: " + Helpers.IsSuccessful(r1));
// Add to a specific machine activation
String machineCode = Helpers.GetMachineCode(2);
BasicResult r2 = Data.AddDataObject(auth, license, machineCode, "sessions", 0, "");
System.out.println("Added to machine: " + Helpers.IsSuccessful(r2));
// Expected: Added to key: true | Added to machine: true
```
--------------------------------
### List Data Objects for License or Activation in Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Retrieve all or filtered data objects associated with a license key or machine activation using ListDataObjects. Useful for reading usage counters, configurations, or metadata.
```java
import io.cryptolens.methods.Data;
import io.cryptolens.models.DataObject;
import io.cryptolens.models.ListOfDataObjectsResult;
// List all data objects for a license key
ListOfDataObjectsResult result = Data.ListDataObjects(auth, license, "");
if (result != null && result.dataObjects != null) {
for (DataObject obj : result.dataObjects) {
System.out.println(obj.Name + " -> int:" + obj.IntValue + " str:" + obj.StringValue);
}
}
// Expected: usage -> int:42 str:
// plan -> int:0 str:enterprise
```
--------------------------------
### License Server Proxy
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Demonstrates how to route Cryptolens API calls through a self-hosted license server by setting the `LicenseServerUrl`.
```APIDOC
## License Server Proxy
### Description
Route all Cryptolens API calls through a self-hosted license server by setting the `LicenseServerUrl` on any request model. This is useful for air-gapped environments or custom network configurations.
### Method
```java
import io.cryptolens.methods.Key;
import io.cryptolens.models.*;
GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080"; // local license server
APIError error = new APIError();
LicenseKey license = Key.GetKey(auth, RSAPubKey, model, error);
if (license == null) {
System.out.println("Error via license server: " + error.message);
} else {
System.out.println("Fetched via local server: " + license.Key);
}
```
### Parameters
* **auth** (String) - Your application's authorization token.
* **RSAPubKey** (String) - The RSA public key for signature verification.
* **GetKeyModel** - Model for getting a license key:
* **productId** (int) - The ID of the product.
* **licenseKey** (String) - The license key to retrieve.
* **LicenseServerUrl** (String) - The URL of the local license server.
* **error** (APIError) - An object to capture API errors.
### Response
* **LicenseKey** - An object containing license details if the key is retrieved successfully.
* **Key** (String) - The license key.
### Error Handling
If the license server is unreachable or returns an error, the `error.message` will contain details.
```
--------------------------------
### Load License from String in Java
Source: https://github.com/cryptolens/cryptolens-java/blob/master/README.md
Loads a license key object from its string representation. Optionally, a maximum number of days can be specified to ensure the license is not too old.
```java
LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString);
```
```java
LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString, 30);
```
--------------------------------
### Activate a License Key with Error Reporting
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Activates a license key for the current machine using the Cryptolens API. Ensure the RSAPubKey and auth token are correctly configured. The machine code is generated using Helpers.GetMachineCode(2). The response is verified locally.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String RSAPubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7...AQAB";
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
// With error reporting
APIError error = new APIError();
LicenseKey license = Key.Activate(
auth,
RSAPubKey,
new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode(2)),
error
);
if (license == null || !Helpers.IsOnRightMachine(license, 2)) {
System.out.println("License invalid. Error: " + error.message);
} else {
System.out.println("License valid! Expires: " + license.Expires);
System.out.println("Feature 1 enabled: " + license.HasFeature(1));
}
// Expected output (success): License valid! Expires: 1893456000
```
--------------------------------
### Persist License Keys for Offline Use
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Serialize a validated `LicenseKey` to a signed string using `SaveAsString` for local storage. `LoadFromString` re-verifies the signature and can reject licenses older than a specified interval, enabling offline verification.
```java
import io.cryptolens.models.LicenseKey;
// After a successful Key.Activate call:
String licenseString = license.SaveAsString();
// Store to file
java.nio.file.Files.writeString(java.nio.file.Path.of("license.lic"), licenseString);
// Later (offline), reload and validate
String stored = java.nio.file.Files.readString(java.nio.file.Path.of("license.lic"));
LicenseKey offlineLicense = LicenseKey.LoadFromString(RSAPubKey, stored, 30); // reject if > 30 days old
if (offlineLicense == null) {
System.out.println("License file invalid or expired.");
} else {
System.out.println("Offline license OK. Expires: " + offlineLicense.Expires);
System.out.println("Product ID: " + offlineLicense.ProductId);
}
// Expected: Offline license OK. Expires: 1893456000
```
--------------------------------
### Floating License Activation - Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Activates a floating license, limiting concurrent users within a defined time interval. `MaxOverdraft` allows exceeding the seat limit temporarily. Ensure `IsOnRightMachine` is called with appropriate floating license parameters.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
String RSAPubKey = "...";
// floatingTimeInterval=300s, maxOverdraft=1
LicenseKey license = Key.Activate(
auth, RSAPubKey,
new ActivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(2), 300, 1)
);
if (license == null || !Helpers.IsOnRightMachine(license, 2, true, true)) {
System.out.println("Floating license check failed.");
} else {
System.out.println("Floating seat acquired. Expires: " + license.Expires);
}
// Expected: Floating seat acquired. Expires:
```
--------------------------------
### Key.CreateTrialKey
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Generates a node-locked, time-limited trial key for the current machine. If a trial key already exists for this machine code, the existing key is returned. Requires feature definitions to include "Time-Limited" and "Trial" flags on the product page.
```APIDOC
## Key.CreateTrialKey — Create a time-limited trial license
### Description
Generates a node-locked, time-limited trial key (default 15 days) for the current machine. If a trial key already exists for this machine code, the existing key is returned. Requires feature definitions to include "Time-Limited" and "Trial" flags on the product page.
### Method
```java
Key.CreateTrialKey(String auth, CreateTrialKeyModel model, APIError error)
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIxMjM0IiwidHJpYWxfdG9rZW4iXQ==";
APIError error = new APIError();
CreateKeyResult result = Key.CreateTrialKey(auth, new CreateTrialKeyModel(3349, Helpers.GetMachineCode(2)), error);
if (result == null || result.result == 1) {
System.out.println("Could not create trial: " + error.message);
} else {
System.out.println("Trial key: " + result.key);
// Expected: Trial key: TRIAL-XXXX-YYYY-ZZZZ
}
```
### Response
#### Success Response (200)
- **result** (int) - Result code.
- **key** (string) - The generated trial key.
#### Response Example
```json
{
"result": 0,
"key": "TRIAL-XXXX-YYYY-ZZZZ"
}
```
```
--------------------------------
### LicenseKey.SaveAsString / LoadFromString
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Persist and load license keys for offline verification. `SaveAsString` serializes a validated `LicenseKey` into a signed string. `LoadFromString` re-verifies the signature and can optionally reject licenses older than a specified number of days.
```APIDOC
## LicenseKey.SaveAsString / LoadFromString
### Description
Serializes a validated `LicenseKey` to a signed string for local storage and loads it back, re-verifying the signature. Optionally rejects files older than a given number of days.
### Method
`LicenseKey.SaveAsString()`
`LicenseKey.LoadFromString(publicKey, licenseString, signatureExpirationInterval)`
### Parameters
#### `SaveAsString`
- None
#### `LoadFromString`
- **publicKey** (string) - The RSA public key for signature verification.
- **licenseString** (string) - The signed license string to load.
- **signatureExpirationInterval** (int) - Optional. Rejects the license if the signature is older than this number of days. Set to 0 to disable.
### Request Example
```java
import io.cryptolens.models.LicenseKey;
// After a successful Key.Activate call:
String licenseString = license.SaveAsString();
// Store to file
java.nio.file.Files.writeString(java.nio.file.Path.of("license.lic"), licenseString);
// Later (offline), reload and validate
String stored = java.nio.file.Files.readString(java.nio.file.Path.of("license.lic"));
LicenseKey offlineLicense = LicenseKey.LoadFromString(RSAPubKey, stored, 30); // reject if > 30 days old
if (offlineLicense == null) {
System.out.println("License file invalid or expired.");
} else {
System.out.println("Offline license OK. Expires: " + offlineLicense.Expires);
System.out.println("Product ID: " + offlineLicense.ProductId);
}
// Expected: Offline license OK. Expires: 1893456000
```
```
--------------------------------
### Retrieve License Key Metadata Without Activation
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Fetches license key details without activating it on a machine. Useful for server-side operations or admin tools. Requires 'GetKey' permission. The optional LicenseServerUrl can route requests through a local license server.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
String RSAPubKey = "...";
APIError error = new APIError();
GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080"; // optional: route through local license server
LicenseKey license = Key.GetKey(auth, RSAPubKey, model, error);
if (license == null) {
System.out.println("Error: " + error.message);
} else {
System.out.println("Key: " + license.Key + " | Block: " + license.Block);
System.out.println("Max machines: " + license.MaxNoOfMachines);
// Expected: Key: ICVLD-VVSZR-ZTICT-YKGXL | Block: false
}
```
--------------------------------
### Route API Calls Through License Server Proxy
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Demonstrates routing Cryptolens API calls through a self-hosted license server by setting the LicenseServerUrl on the request model. This is useful for air-gapped deployments.
```java
import io.cryptolens.methods.Key;
import io.cryptolens.models.*;
GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080"; // local license server
APIError error = new APIError();
LicenseKey license = Key.GetKey(auth, RSAPubKey, model, error);
if (license == null) {
System.out.println("Error via license server: " + error.message);
} else {
System.out.println("Fetched via local server: " + license.Key);
}
// Expected: Fetched via local server: ICVLD-VVSZR-ZTICT-YKGXL
```
--------------------------------
### Key.ExtendLicense
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Extends a license by a given number of days. For SKGL algorithm products the key string may change; for SKM15 it stays the same. Requires `ExtendLicense` permission on the access token.
```APIDOC
## Key.ExtendLicense — Extend a license's expiry date
### Description
Extends a license by a given number of days. For SKGL algorithm products the key string may change; for SKM15 it stays the same. Requires `ExtendLicense` permission on the access token.
### Method
```java
Key.ExtendLicense(String auth, ExtendLicenseModel model, APIError error)
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIxMjM0IiwiZXh0ZW5kX3Rva2VuIl0=";
APIError error = new APIError();
// Extend product 3349, key "ICVLD-VVSZR-ZTICT-YKGXL" by 30 days
boolean ok = Key.ExtendLicense(auth, new ExtendLicenseModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", 30), error);
System.out.println(ok ? "Extended by 30 days." : "Error: " + error.message);
// Expected: Extended by 30 days.
```
### Response
#### Success Response (200)
- **result** (boolean) - True if the license was extended successfully, false otherwise.
#### Response Example
```json
{
"result": true
}
```
```
--------------------------------
### Key.GetKey — Retrieve a license key without activating
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Fetches a license key object from Cryptolens without registering a new machine activation. Useful for reading key metadata server-side or in admin tools. Requires an access token with `GetKey` permission. The response is also RSA-signed and verified locally.
```APIDOC
## Key.GetKey — Retrieve a license key without activating
### Description
Fetches a license key object from Cryptolens without registering a new machine activation. Useful for reading key metadata server-side or in admin tools. Requires an access token with `GetKey` permission. The response is also RSA-signed and verified locally.
### Method
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
String RSAPubKey = "...";
APIError error = new APIError();
GetKeyModel model = new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL");
model.LicenseServerUrl = "http://10.1.1.6:8080"; // optional: route through local license server
LicenseKey license = Key.GetKey(auth, RSAPubKey, model, error);
if (license == null) {
System.out.println("Error: " + error.message);
} else {
System.out.println("Key: " + license.Key + " | Block: " + license.Block);
System.out.println("Max machines: " + license.MaxNoOfMachines);
// Expected: Key: ICVLD-VVSZR-ZTICT-YKGXL | Block: false
}
```
```
--------------------------------
### GetProducts
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Retrieves all products associated with the account linked to the access token. This is useful for multi-product applications that need to dynamically look up product IDs at runtime.
```APIDOC
## GetProducts
### Description
Returns all products associated with the account linked to the access token. Useful for multi-product applications that dynamically look up product IDs at runtime.
### Method
```java
ProductMethods.GetProducts(prodAuth)
```
### Parameters
* **prodAuth** (String) - Required - The product authorization token.
### Response
* **GetProductsResult** - Contains a list of `Product` objects.
* **products** (List) - A list of available products.
* **Id** (int) - The unique identifier for the product.
* **Name** (String) - The name of the product.
### Request Example
```java
String prodAuth = "WyIxMjM0IiwiZ2V0cHJvZHVjdHNfdG9rZW4iXQ==";
GetProductsResult result = ProductMethods.GetProducts(prodAuth);
if (result != null && result.products != null) {
for (Product p : result.products) {
System.out.println("Product: " + p.Name + " (ID: " + p.Id + ")");
}
}
```
### Response Example
```
Product: My Software (ID: 3349)
```
```
--------------------------------
### Data.AddDataObject
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Attach metadata to a license key or a specific machine activation. Data objects are used for usage-based licensing. Requires `AddDataObject` permission.
```APIDOC
## Data.AddDataObject
### Description
Adds a named data object (key/value pair) to a license key or a specific machine activation. Used for usage-based licensing.
### Method
`Data.AddDataObject(auth, license, name, value, checkForDuplicates, machineCode)`
`Data.AddDataObject(auth, license, name, value, machineCode)`
### Parameters
- **auth** (Auth) - The authentication object.
- **license** (LicenseKey) - The license object.
- **name** (string) - The name of the data object.
- **value** (string or int) - The value of the data object. For integer counters, use `0` initially.
- **checkForDuplicates** (boolean) - Optional. If true, prevents adding duplicate data objects.
- **machineCode** (string) - Optional. If provided, the data object is added to the specified machine activation instead of the license key.
### Request Example
```java
import io.cryptolens.methods.Data;
import io.cryptolens.internal.BasicResult;
// Add to license key
BasicResult r1 = Data.AddDataObject(auth, license, "usage", 0, "", true); // checkForDuplicates=true
System.out.println("Added to key: " + Helpers.IsSuccessful(r1));
// Add to a specific machine activation
String machineCode = Helpers.GetMachineCode(2);
BasicResult r2 = Data.AddDataObject(auth, license, machineCode, "sessions", 0, "");
System.out.println("Added to machine: " + Helpers.IsSuccessful(r2));
// Expected: Added to key: true | Added to machine: true
```
```
--------------------------------
### Save License to String in Java
Source: https://github.com/cryptolens/cryptolens-java/blob/master/README.md
Saves an activated license key object to a string representation. This is useful for offline storage and retrieval.
```java
String licenseString = license.SaveAsString();
```
--------------------------------
### Data.ListDataObjects
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Returns all (or filtered) data objects attached to a license key or a specific machine activation. Useful for reading stored usage counters, feature configuration, or metadata on the client.
```APIDOC
## Data.ListDataObjects — Retrieve data objects for a license or activation
Returns all (or filtered) data objects attached to a license key or a specific machine activation. Useful for reading stored usage counters, feature configuration, or metadata on the client.
```java
import io.cryptolens.methods.Data;
import io.cryptolens.models.DataObject;
import io.cryptolens.models.ListOfDataObjectsResult;
// List all data objects for a license key
ListOfDataObjectsResult result = Data.ListDataObjects(auth, license, "");
if (result != null && result.dataObjects != null) {
for (DataObject obj : result.dataObjects) {
System.out.println(obj.Name + " -> int:" + obj.IntValue + " str:" + obj.StringValue);
}
}
// Expected: usage -> int:42 str:
// plan -> int:0 str:enterprise
```
```
--------------------------------
### Subscription.RecordUsage
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Reports a metered usage increment to Cryptolens, which forwards it to Stripe's metered billing API. Requires the recurring billing module to be configured and an access token with `Subscription` permission.
```APIDOC
## Subscription.RecordUsage — Record metered billing usage
Reports a metered usage increment to Cryptolens, which forwards it to Stripe's metered billing API. Requires the recurring billing module to be configured and an access token with `Subscription` permission.
```java
import io.cryptolens.methods.Subscription;
import io.cryptolens.models.RecordUsageModel;
import io.cryptolens.internal.BasicResult;
String subscriptionAuth = "WyIxMjM0Iiwic3Vic2NyaXB0aW9uX3Rva2VuIl0=";
// Record 5 API calls for metered billing
BasicResult result = Subscription.RecordUsage(
subscriptionAuth,
new RecordUsageModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", 5)
);
System.out.println("Usage recorded: " + Helpers.IsSuccessful(result));
// Expected: Usage recorded: true
```
```
--------------------------------
### Activate Floating License with Overdraft
Source: https://github.com/cryptolens/cryptolens-java/blob/master/README.md
Enables floating licenses with a specified time interval and allows customers to exceed the bound. Requires specific flags set to true in `Helpers.IsOnRightMachine`.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
public static void main(String args[]) {
String RSAPubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==AQAB";
String auth = "WyIyNjA5IiwiaWE5b0VFT3Q2eDlNR2FvbHBHK2VOYUZ4bzNjT3h5UkNrMCtiYnhPRSJd";
LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(2), 300, 1));
if (license == null || !Helpers.IsOnRightMachine(license, 2, 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);
}
}
```
--------------------------------
### Helpers.IsOnRightMachine
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Verifies whether the current machine's fingerprint appears in the license's `ActivatedMachines` list. Supports node-locked, floating, and overdraft scenarios. Can also accept a custom machine code string for platforms where `GetMachineCode` is unavailable.
```APIDOC
## Helpers.IsOnRightMachine — Verify the device matches the license
### Description
Checks whether the current machine's fingerprint appears in the license's `ActivatedMachines` list. Supports node-locked, floating, and overdraft scenarios. Can also accept a custom machine code string for platforms where `GetMachineCode` is unavailable (e.g., Android).
### Method
```java
Helpers.IsOnRightMachine(LicenseKey license, int version)
Helpers.IsOnRightMachine(LicenseKey license, int version, boolean isFloatingLicense, boolean allowOverdraft)
Helpers.IsOnRightMachine(LicenseKey license, String customMachineCode)
```
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```java
import io.cryptolens.methods.Helpers;
import io.cryptolens.models.LicenseKey;
// Node-locked
boolean valid = Helpers.IsOnRightMachine(license, 2);
// Floating with overdraft
boolean validFloat = Helpers.IsOnRightMachine(license, 2, true, true);
// Custom machine code (e.g., Android)
String androidId = "my-android-device-hash";
boolean validAndroid = Helpers.IsOnRightMachine(license, androidId);
System.out.println("On right machine: " + valid);
// Expected: On right machine: true
```
### Response
#### Success Response (200)
- **result** (boolean) - True if the machine matches the license, false otherwise.
#### Response Example
```json
{
"result": true
}
```
```
--------------------------------
### Add Maven Dependency for Cryptolens Java Client
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Include the Cryptolens Java client library in your Maven project by adding the specified dependency to your pom.xml file.
```xml
io.cryptolens
cryptolens
1.27.0
```
--------------------------------
### Track Analytics Events in Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Send custom analytics events to Cryptolens using RegisterEvent. Can be used standalone with a machine code or with full product/key context for richer insights.
```java
import io.cryptolens.methods.AI;
import io.cryptolens.models.RegisterEventModel;
import io.cryptolens.internal.BasicResult;
String aiAuth = "WyIxMjM0IiwiYWlfdG9rZW4iXQ==";
BasicResult result = AI.RegisterEvent(
aiAuth,
new RegisterEventModel(
3349, // productId
"ICVLD-VVSZR-ZTICT-YKGXL", // key
Helpers.GetMachineCode(2), // machineCode
"export", // featureName
"pdf_export_clicked", // eventName
1, // value
"USD" // currency
)
);
System.out.println("Event registered: " + Helpers.IsSuccessful(result));
// Expected: Event registered: true
```
--------------------------------
### Extend License - Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Extends an existing license by a specified number of days. For SKGL products, the key string might change. Requires the 'ExtendLicense' permission for the access token.
```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;
String auth = "WyIxMjM0IiwiZXh0ZW5kX3Rva2VuIl0=";
APIError error = new APIError();
// Extend product 3349, key "ICVLD-VVSZR-ZTICT-YKGXL" by 30 days
boolean ok = Key.ExtendLicense(auth, new ExtendLicenseModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", 30), error);
System.out.println(ok ? "Extended by 30 days." : "Error: " + error.message);
// Expected: Extended by 30 days.
```
--------------------------------
### Activate License Key on Android
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Activates a license key on Android, ensuring network calls run on a background thread. Uses a custom machine identifier and handles UI updates on the main thread.
```java
// In an Activity or ViewModel
Thread thread = new Thread(() -> {
String mid = Helpers.SHA256(
android.provider.Settings.Secure.getString(
getContentResolver(),
android.provider.Settings.Secure.ANDROID_ID));
LicenseKey license = Key.Activate(auth, RSAPubKey,
new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", mid));
runOnUiThread(() -> {
if (license == null || !Helpers.IsOnRightMachine(license, mid)) {
statusText.setText("License invalid.");
} else {
statusText.setText("License valid! Expires: " + license.Expires);
}
});
});
thread.start();
```
--------------------------------
### Retrieve Broadcasted Messages in Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Fetch broadcasted messages for a product, filterable by time and channel, using GetMessages. Useful for announcements or feature flags.
```java
import io.cryptolens.methods.Message;
import io.cryptolens.models.*;
String msgAuth = "WyIxMjM0IiwibXNnX3Rva2VuIl0=";
GetMessagesModel model = new GetMessagesModel();
model.Channel = "stable";
model.Time = 0; // all messages since Unix epoch
APIError error = new APIError();
GetMessagesResult result = Message.GetMessages(msgAuth, model, error);
if (result == null || result.result == 1) {
System.out.println("Error: " + error.message);
} else {
for (MessageObject msg : result.messages) {
System.out.println("[" + msg.Channel + "] " + msg.Content);
}
}
// Expected: [stable] Version 2.5 released with new features.
```
--------------------------------
### Record Metered Billing Usage in Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Report metered usage increments to Cryptolens for forwarding to Stripe's metered billing API using RecordUsage. Requires the recurring billing module to be configured.
```java
import io.cryptolens.methods.Subscription;
import io.cryptolens.models.RecordUsageModel;
import io.cryptolens.internal.BasicResult;
String subscriptionAuth = "WyIxMjM0Iiwic3Vic2NyaXB0aW9uX3Rva2VuIl0=";
// Record 5 API calls for metered billing
BasicResult result = Subscription.RecordUsage(
subscriptionAuth,
new RecordUsageModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", 5)
);
System.out.println("Usage recorded: " + Helpers.IsSuccessful(result));
// Expected: Usage recorded: true
```
--------------------------------
### Verify Machine Code - Java
Source: https://context7.com/cryptolens/cryptolens-java/llms.txt
Verifies if the current machine matches the license's activated machines list. Supports node-locked, floating, and overdraft scenarios. Can also use a custom machine code string for platforms like Android.
```java
import io.cryptolens.methods.Helpers;
import io.cryptolens.models.LicenseKey;
// Node-locked
boolean valid = Helpers.IsOnRightMachine(license, 2);
// Floating with overdraft
boolean validFloat = Helpers.IsOnRightMachine(license, 2, true, true);
// Custom machine code (e.g., Android)
String androidId = "my-android-device-hash";
boolean validAndroid = Helpers.IsOnRightMachine(license, androidId);
System.out.println("On right machine: " + valid);
// Expected: On right machine: true
```