The Algorithm class represents an algorithm to be used in the Signing or Verification process of a Token. This class and its subclasses are thread-safe.
| 14 | * This class and its subclasses are thread-safe. |
| 15 | */ |
| 16 | @SuppressWarnings("WeakerAccess") |
| 17 | public abstract class Algorithm { |
| 18 | |
| 19 | private final String name; |
| 20 | private final String description; |
| 21 | |
| 22 | /** |
| 23 | * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". |
| 24 | * |
| 25 | * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. |
| 26 | * @return a valid RSA256 Algorithm. |
| 27 | * @throws IllegalArgumentException if the provided Key is null. |
| 28 | */ |
| 29 | public static Algorithm RSA256(RSAKeyProvider keyProvider) throws IllegalArgumentException { |
| 30 | return new RSAAlgorithm("RS256", "SHA256withRSA", keyProvider); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". |
| 35 | * |
| 36 | * @param publicKey the key to use in the verify instance. |
| 37 | * @param privateKey the key to use in the signing instance. |
| 38 | * @return a valid RSA256 Algorithm. |
| 39 | * @throws IllegalArgumentException if both provided Keys are null. |
| 40 | */ |
| 41 | public static Algorithm RSA256(RSAPublicKey publicKey, RSAPrivateKey privateKey) throws IllegalArgumentException { |
| 42 | return RSA256(RSAAlgorithm.providerForKeys(publicKey, privateKey)); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Creates a new Algorithm instance using SHA256withRSA. Tokens specify this as "RS256". |
| 47 | * |
| 48 | * @param key the key to use in the verify or signing instance. |
| 49 | * @return a valid RSA256 Algorithm. |
| 50 | * @throws IllegalArgumentException if the Key Provider is null. |
| 51 | */ |
| 52 | public static Algorithm RSA256(RSAKey key) throws IllegalArgumentException { |
| 53 | RSAPublicKey publicKey = key instanceof RSAPublicKey ? (RSAPublicKey) key : null; |
| 54 | RSAPrivateKey privateKey = key instanceof RSAPrivateKey ? (RSAPrivateKey) key : null; |
| 55 | return RSA256(publicKey, privateKey); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". |
| 60 | * |
| 61 | * @param keyProvider the provider of the Public Key and Private Key for the verify and signing instance. |
| 62 | * @return a valid RSA384 Algorithm. |
| 63 | * @throws IllegalArgumentException if the Key Provider is null. |
| 64 | */ |
| 65 | public static Algorithm RSA384(RSAKeyProvider keyProvider) throws IllegalArgumentException { |
| 66 | return new RSAAlgorithm("RS384", "SHA384withRSA", keyProvider); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Creates a new Algorithm instance using SHA384withRSA. Tokens specify this as "RS384". |
| 71 | * |
| 72 | * @param publicKey the key to use in the verify instance. |
| 73 | * @param privateKey the key to use in the signing instance. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…