Skip to content

Commit

Permalink
Merge pull request #95 from buttercookie42/fixandroid
Browse files Browse the repository at this point in the history
Fix license verification failures on Android
  • Loading branch information
verhas authored Dec 16, 2024
2 parents 4db59e7 + ddde5b5 commit f661188
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
--add-opens com.javax0.license3j/javax0.license3j.io=ALL-UNNAMED
--add-opens com.javax0.license3j/javax0.license3j.parsers=ALL-UNNAMED
--add-opens com.javax0.license3j/javax0.license3j.hardware=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
</argLine>
</configuration>
<dependencies>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/javax0/license3j/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ public void sign(PrivateKey key, String digest) throws NoSuchAlgorithmException,
*/
public boolean isOK(byte[] key) {
try {
return isOK(LicenseKeyPair.Create.from(key, Modifier.PUBLIC).getPair().getPublic());
LicenseKeyPair lkp = LicenseKeyPair.Create.from(key, Modifier.PUBLIC);
return isOK(lkp.getPair().getPublic(), lkp.cipher());
} catch (Exception e) {
return false;
}
Expand All @@ -154,11 +155,15 @@ public boolean isOK(byte[] key) {
* false}.
*/
public boolean isOK(PublicKey key) {
return isOK(key, key.getAlgorithm());
}

private boolean isOK(PublicKey key, String algorithm) {
try {
final var digester = MessageDigest.getInstance(get(DIGEST_KEY).getString());
final var ser = unsigned();
final var digestValue = digester.digest(ser);
final var cipher = Cipher.getInstance(key.getAlgorithm());
final var cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.DECRYPT_MODE, key);
final var sigDigest = cipher.doFinal(getSignature());
return Arrays.equals(digestValue, sigDigest);
Expand Down

0 comments on commit f661188

Please sign in to comment.