diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 05d3222..0b033fe 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -7,7 +7,6 @@
-
@@ -20,25 +19,27 @@
+
-
+
-
+
+
-
-
+
+
-
-
+
+
@@ -46,22 +47,19 @@
-
+
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
@@ -70,19 +68,10 @@
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
@@ -102,8 +91,8 @@
-
-
+
+
@@ -117,11 +106,11 @@
-
+
-
-
+
+
@@ -129,11 +118,20 @@
+
+
+
+
+
+
+
+
+
-
+
@@ -174,12 +172,10 @@
-
-
@@ -187,6 +183,8 @@
+
+
@@ -197,7 +195,7 @@
-
+
@@ -307,8 +305,8 @@
-
+
@@ -460,10 +458,9 @@
-
-
+
-
+
@@ -558,13 +555,6 @@
-
-
-
-
-
-
-
@@ -572,61 +562,71 @@
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
@@ -637,27 +637,24 @@
-
+
-
-
+
+
-
+
-
-
-
-
-
+
+
-
+
-
-
+
+
diff --git a/README.md b/README.md
index 5dd0fa2..84c7eea 100644
--- a/README.md
+++ b/README.md
@@ -53,4 +53,32 @@ When loading it back, we can use the code below:
```java
LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString);
-```
\ No newline at end of file
+```
+
+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).
+```java
+LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString, 30);
+```
+
+### Floating licenses
+[Floating licenses](https://help.cryptolens.io/licensing-models/floating) 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.
+
+```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(), 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);
+ }
+}
+```
diff --git a/example-app/src/Main.java b/example-app/src/Main.java
index faf1ae1..fac9f54 100644
--- a/example-app/src/Main.java
+++ b/example-app/src/Main.java
@@ -4,13 +4,12 @@
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()));
- System.out.println(license);
-
if (license == null || !Helpers.IsOnRightMachine(license)) {
System.out.println("The license does not work.");
} else {
@@ -20,9 +19,24 @@ public static void main(String[] args) {
// Saving and loading a license (for offline use)
String licenseString = license.SaveAsString();
- LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString);
+ LicenseKey newLicense = LicenseKey.LoadFromString(RSAPubKey, licenseString, 1);
System.out.println(newLicense.Expires);
}
+
+ }
+
+ public static void main2() {
+ 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(),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);
+ }
}
}
diff --git a/pom.xml b/pom.xml
index 5e690e9..0c8f372 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.cryptolens
cryptolens
jar
- 1.4
+ 1.5
cryptolens
A client api to access Cryptolens Licensing API.
https://github.com/cryptolens/cryptolens-java
diff --git a/src/main/java/io/cryptolens/models/ActivateModel.java b/src/main/java/io/cryptolens/models/ActivateModel.java
index e91f9f9..5cbd8bb 100644
--- a/src/main/java/io/cryptolens/models/ActivateModel.java
+++ b/src/main/java/io/cryptolens/models/ActivateModel.java
@@ -52,6 +52,22 @@ public ActivateModel(int productId, String key, String machineCode) {
Key = key;
MachineCode = machineCode;
}
+
+ public ActivateModel(int productId, String key, String machineCode, int floatingTimeInterval) {
+ ProductId = productId;
+ Key = key;
+ MachineCode = machineCode;
+ FloatingTimeInterval = floatingTimeInterval;
+ }
+
+ public ActivateModel(int productId, String key, String machineCode, int floatingTimeInterval, int maxOverdraft) {
+ ProductId = productId;
+ Key = key;
+ MachineCode = machineCode;
+ FloatingTimeInterval = floatingTimeInterval;
+ MaxOverdraft = maxOverdraft;
+ }
+
public ActivateModel(int productId, String key, String machineCode, int fieldsToReturn, boolean metadata, int floatingTimeInterval, int maxOverdraft) {
ProductId = productId;
Key = key;
diff --git a/src/main/java/io/cryptolens/models/LicenseKey.java b/src/main/java/io/cryptolens/models/LicenseKey.java
index 50981b2..ae6de5c 100644
--- a/src/main/java/io/cryptolens/models/LicenseKey.java
+++ b/src/main/java/io/cryptolens/models/LicenseKey.java
@@ -46,14 +46,28 @@ public String SaveAsString() {
return RawResponse;
}
+
/**
* Load a license string (created with @see SaveAsString) into a license object.
* Note, signature verification will be performed under the hood.
* @param RSAPubKey Your RSA Public Key, which can be found here.
* @param licenseString The license key object stored as a string.
- * @return A new license key object or null (if an error has occurred).
*/
public static LicenseKey LoadFromString(String RSAPubKey, String licenseString) {
+ return LoadFromString(RSAPubKey, licenseString, -1);
+ }
+
+ /**
+ * Load a license string (created with @see SaveAsString) into a license object.
+ * Note, signature verification will be performed under the hood.
+ * @param RSAPubKey Your RSA Public Key, which can be found here.
+ * @param licenseString The license key object stored as a string.
+ * @param signatureExpirationInterval If the license key was signed, this method
+ * will check so that no more than "signatureExpirationInterval"
+ * days have passed since the last activation.
+ * @return A new license key object or null (if an error has occurred).
+ */
+ public static LicenseKey LoadFromString(String RSAPubKey, String licenseString, int signatureExpirationInterval) {
ActivateResult result = new Gson().fromJson(licenseString, ActivateResult.class);
@@ -82,6 +96,16 @@ public static LicenseKey LoadFromString(String RSAPubKey, String licenseString)
LicenseKey license = new Gson().fromJson(s, LicenseKey.class);
license.RawResponse = licenseString;
+ if(signatureExpirationInterval > 0) {
+ long unixTime = System.currentTimeMillis() / 1000L;
+
+ if(license.SignDate + 0x15180*signatureExpirationInterval < unixTime) {
+ // the license file has expired.
+ System.err.println("The license file has expired.");
+ return null;
+ }
+ }
+
return license;
}
}