diff --git a/pom.xml b/pom.xml index c3c6130..518729e 100755 --- a/pom.xml +++ b/pom.xml @@ -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 diff --git a/src/main/java/javax0/license3j/License.java b/src/main/java/javax0/license3j/License.java index 3f963fb..d75deb5 100644 --- a/src/main/java/javax0/license3j/License.java +++ b/src/main/java/javax0/license3j/License.java @@ -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; } @@ -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);