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 fc05b924..ec4ab405 100644 --- a/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java +++ b/lib/src/main/java/com/auth0/jwt/algorithms/Algorithm.java @@ -28,6 +28,18 @@ public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumen return new RSAAlgorithm("RS256", "SHA256withRSA", keyProvider); } + /** + * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". + * + * @param publicKey the key to use in the verify instance. + * @param privateKey the key to use in the signing instance. + * @return a valid RSA256 Algorithm. + * @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); + } + /** * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". * @@ -46,66 +58,50 @@ public static Algorithm RSA256(RSAKey key) throws IllegalArgumentException { /** * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". * - * @param key the key to use in the verify or signing instance. + * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. * @return a valid RSA384 Algorithm. - * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} + * @throws IllegalArgumentException if the Key Provider is null. */ - @Deprecated - public static Algorithm RSA384(RSAKey key) throws IllegalArgumentException { - RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null; - RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null; - return RSA384(publicKey, privateKey); + public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumentException { + return new RSAAlgorithm("RS384", "SHA384withRSA", keyProvider); } /** * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". * - * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @param publicKey the key to use in the verify instance. + * @param privateKey the key to use in the signing instance. * @return a valid RSA384 Algorithm. - * @throws IllegalArgumentException if the Key Provider is null. + * @throws IllegalArgumentException if both provided Keys are null. */ - public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumentException { - return new RSAAlgorithm("RS384", "SHA384withRSA", keyProvider); + public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { + return new RSAAlgorithm("RS384", "SHA384withRSA", publicKey, privateKey); } /** - * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512". + * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". * * @param key the key to use in the verify or signing instance. - * @return a valid RSA512 Algorithm. + * @return a valid RSA384 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} + * @deprecated use {@link #RSA384(RSAPublicKey, RSAPrivateKey)} */ @Deprecated - public static Algorithm RSA512(RSAKey key) throws IllegalArgumentException { + public static Algorithm RSA384(RSAKey key) throws IllegalArgumentException { RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null; RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null; - return RSA512(publicKey, privateKey); - } - - /** - * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". - * - * @param publicKey the key to use in the verify instance. - * @param privateKey the key to use in the signing instance. - * @return a valid RSA256 Algorithm. - * @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 RSA384(publicKey, privateKey); } /** - * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". + * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512". * - * @param publicKey the key to use in the verify instance. - * @param privateKey the key to use in the signing instance. - * @return a valid RSA384 Algorithm. - * @throws IllegalArgumentException if both provided Keys are null. + * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @return a valid RSA512 Algorithm. + * @throws IllegalArgumentException if the Key Provider is null. */ - public static Algorithm RSA384(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { - return new RSAAlgorithm("RS384", "SHA384withRSA", publicKey, privateKey); + public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumentException { + return new RSAAlgorithm("RS512", "SHA512withRSA", keyProvider); } /** @@ -123,12 +119,16 @@ public static Algorithm RSA512(RSAPublicKey publicKey, RSAPrivateKey privateKey) /** * Creates a new Algorithm instance using SHA512withRSA. Tokens specify this as "RS512". * - * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @param key the key to use in the verify or signing instance. * @return a valid RSA512 Algorithm. - * @throws IllegalArgumentException if the Key Provider is null. + * @throws IllegalArgumentException if the provided Key is null. + * @deprecated use {@link #RSA512(RSAPublicKey, RSAPrivateKey)} */ - public static Algorithm RSA512(RSAKeyProvider keyProvider) throws IllegalArgumentException { - return new RSAAlgorithm("RS512", "SHA512withRSA", keyProvider); + @Deprecated + public static Algorithm RSA512(RSAKey key) throws IllegalArgumentException { + RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null; + RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null; + return RSA512(publicKey, privateKey); } /** @@ -203,42 +203,39 @@ public static Algorithm HMAC512(byte[] secret) throws IllegalArgumentException { /** * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256". * - * @param key the key to use in the verify or signing instance. + * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. * @return a valid ECDSA256 Algorithm. - * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} + * @throws IllegalArgumentException if the Key Provider is null. */ - @Deprecated - public static Algorithm ECDSA256(ECKey key) throws IllegalArgumentException { - ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null; - ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null; - return ECDSA256(publicKey, privateKey); + public static Algorithm ECDSA256(ECKeyProvider keyProvider) throws IllegalArgumentException { + return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, keyProvider); } /** * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256". * - * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @param publicKey the key to use in the verify instance. + * @param privateKey the key to use in the signing instance. * @return a valid ECDSA256 Algorithm. - * @throws IllegalArgumentException if the Key Provider is null. + * @throws IllegalArgumentException if the provided Key is null. */ - public static Algorithm ECDSA256(ECKeyProvider keyProvider) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, keyProvider); + public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { + return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, publicKey, privateKey); } /** - * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384". + * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256". * * @param key the key to use in the verify or signing instance. - * @return a valid ECDSA384 Algorithm. + * @return a valid ECDSA256 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} + * @deprecated use {@link #ECDSA256(ECPublicKey, ECPrivateKey)} */ @Deprecated - public static Algorithm ECDSA384(ECKey key) throws IllegalArgumentException { + public static Algorithm ECDSA256(ECKey key) throws IllegalArgumentException { ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null; ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null; - return ECDSA384(publicKey, privateKey); + return ECDSA256(publicKey, privateKey); } /** @@ -253,42 +250,41 @@ public static Algorithm ECDSA384(ECKeyProvider keyProvider) throws IllegalArgume } /** - * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512". + * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384". * - * @param key the key to use in the verify or signing instance. - * @return a valid ECDSA512 Algorithm. + * @param publicKey the key to use in the verify instance. + * @param privateKey the key to use in the signing instance. + * @return a valid ECDSA384 Algorithm. * @throws IllegalArgumentException if the provided Key is null. - * @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} */ - @Deprecated - public static Algorithm ECDSA512(ECKey key) throws IllegalArgumentException { - ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null; - ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null; - return ECDSA512(publicKey, privateKey); + public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { + return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, publicKey, privateKey); } /** - * Creates a new Algorithm instance using SHA256withECDSA. Tokens specify this as "ES256". + * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384". * - * @param publicKey the key to use in the verify instance. - * @param privateKey the key to use in the signing instance. - * @return a valid ECDSA256 Algorithm. + * @param key the key to use in the verify or signing instance. + * @return a valid ECDSA384 Algorithm. * @throws IllegalArgumentException if the provided Key is null. + * @deprecated use {@link #ECDSA384(ECPublicKey, ECPrivateKey)} */ - public static Algorithm ECDSA256(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES256", "SHA256withECDSA", 32, publicKey, privateKey); + @Deprecated + public static Algorithm ECDSA384(ECKey key) throws IllegalArgumentException { + ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null; + ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null; + return ECDSA384(publicKey, privateKey); } /** - * Creates a new Algorithm instance using SHA384withECDSA. Tokens specify this as "ES384". + * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512". * - * @param publicKey the key to use in the verify instance. - * @param privateKey the key to use in the signing instance. - * @return a valid ECDSA384 Algorithm. - * @throws IllegalArgumentException if the provided Key is null. + * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @return a valid ECDSA512 Algorithm. + * @throws IllegalArgumentException if the Key Provider is null. */ - public static Algorithm ECDSA384(ECPublicKey publicKey, ECPrivateKey privateKey) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES384", "SHA384withECDSA", 48, publicKey, privateKey); + public static Algorithm ECDSA512(ECKeyProvider keyProvider) throws IllegalArgumentException { + return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, keyProvider); } /** @@ -306,14 +302,19 @@ public static Algorithm ECDSA512(ECPublicKey publicKey, ECPrivateKey privateKey) /** * Creates a new Algorithm instance using SHA512withECDSA. Tokens specify this as "ES512". * - * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. + * @param key the key to use in the verify or signing instance. * @return a valid ECDSA512 Algorithm. - * @throws IllegalArgumentException if the Key Provider is null. + * @throws IllegalArgumentException if the provided Key is null. + * @deprecated use {@link #ECDSA512(ECPublicKey, ECPrivateKey)} */ - public static Algorithm ECDSA512(ECKeyProvider keyProvider) throws IllegalArgumentException { - return new ECDSAAlgorithm("ES512", "SHA512withECDSA", 66, keyProvider); + @Deprecated + public static Algorithm ECDSA512(ECKey key) throws IllegalArgumentException { + ECPublicKey publicKey = key instanceof ECPublicKey ? (ECPublicKey) key : null; + ECPrivateKey privateKey = key instanceof ECPrivateKey ? (ECPrivateKey) key : null; + return ECDSA512(publicKey, privateKey); } + public static Algorithm none() { return new NoneAlgorithm(); }