diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java index ec4ab405..a58558f3 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java @@ -37,7 +37,7 @@ public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS256", "SHA256withRSA", publicKey, privateKey); + return new RSAAlgorithm("RS256", "SHA256withRSA", RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -75,7 +75,7 @@ public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS384", "SHA384withRSA", publicKey, privateKey); + return new RSAAlgorithm("RS384", "SHA384withRSA", RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -113,7 +113,7 @@ public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumen * @throws IllegalArgumentException if both provided Keys are null. */ public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS512", "SHA512withRSA", publicKey, privateKey); + return new RSAAlgorithm("RS512", "SHA512withRSA", RSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -220,7 +220,7 @@ public static Algorithm ECDSA256(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, publicKey, privateKey); + return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -258,7 +258,7 @@ public static Algorithm ECDSA384(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, publicKey, privateKey); + return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** @@ -296,7 +296,7 @@ public static Algorithm ECDSA512(ECKeyProvider keyProvider) throws IllegalArgume * @throws IllegalArgumentException if the provided Key is null. */ public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, publicKey, privateKey); + return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, ECDSAAlgorithm.providerForKeys(publicKey, privateKey)); } /** diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java index 04c95599..2b43c7e6 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java @@ -30,10 +30,6 @@ class ECDSAAlgorithm extends Algorithm { this.ecNumberSize = ecNumberSize; } - ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - this(new CryptoHelper(), id, algorithm, ecNumberSize, providerForKeys(publicKey, privateKey)); - } - ECDSAAlgorithm(String id, String algorithm, int ecNumberSize, ECKeyProvider keyProvider) throws IllegalArgumentException { this(new CryptoHelper(), id, algorithm, ecNumberSize, keyProvider); } diff --git a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java b/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java index c9f708d6..a5d7d3f3 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/RSAAlgorithm.java @@ -28,10 +28,6 @@ class RSAAlgorithm extends Algorithm { this.crypto = crypto; } - RSAAlgorithm(String id, String algorithm, RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - this(new CryptoHelper(), id, algorithm, providerForKeys(publicKey, privateKey)); - } - RSAAlgorithm(String id, String algorithm, RSAKeyProvider keyProvider) throws IllegalArgumentException { this(new CryptoHelper(), id, algorithm, keyProvider); } diff --git a/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java b/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java index 40f484b2..b169b554 100644 --- a/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java +++ b/lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java @@ -336,7 +336,8 @@ public void shouldFailJOSEToDERConversionOnInvalidJOSESignatureLength() throws E ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC"); ECPrivateKey privateKey = mock(ECPrivateKey.class); - Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, publicKey, privateKey); + ECKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey); + Algorithm algorithm = new ECDSAAlgorithm("ES256", "SHA256withECDSA", 128, provider); AlgorithmUtils.verify(algorithm, jwt); }