public abstract class Algorithm
extends java.lang.Object
Modifier | Constructor and Description |
---|---|
protected |
Algorithm(java.lang.String name,
java.lang.String description) |
Modifier and Type | Method and Description |
---|---|
static Algorithm |
ECDSA256(ECDSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA256withECDSA.
|
static Algorithm |
ECDSA256(java.security.interfaces.ECKey key)
Deprecated.
|
static Algorithm |
ECDSA256(java.security.interfaces.ECPublicKey publicKey,
java.security.interfaces.ECPrivateKey privateKey)
Creates a new Algorithm instance using SHA256withECDSA.
|
static Algorithm |
ECDSA384(ECDSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA384withECDSA.
|
static Algorithm |
ECDSA384(java.security.interfaces.ECKey key)
Deprecated.
|
static Algorithm |
ECDSA384(java.security.interfaces.ECPublicKey publicKey,
java.security.interfaces.ECPrivateKey privateKey)
Creates a new Algorithm instance using SHA384withECDSA.
|
static Algorithm |
ECDSA512(ECDSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA512withECDSA.
|
static Algorithm |
ECDSA512(java.security.interfaces.ECKey key)
Deprecated.
|
static Algorithm |
ECDSA512(java.security.interfaces.ECPublicKey publicKey,
java.security.interfaces.ECPrivateKey privateKey)
Creates a new Algorithm instance using SHA512withECDSA.
|
java.lang.String |
getName()
Getter for the name of this Algorithm, as defined in the JWT Standard.
|
java.lang.String |
getSigningKeyId()
Getter for the Id of the Private Key used to sign the tokens.
|
static Algorithm |
HMAC256(byte[] secret)
Creates a new Algorithm instance using HmacSHA256.
|
static Algorithm |
HMAC256(java.lang.String secret)
Creates a new Algorithm instance using HmacSHA256.
|
static Algorithm |
HMAC384(byte[] secret)
Creates a new Algorithm instance using HmacSHA384.
|
static Algorithm |
HMAC384(java.lang.String secret)
Creates a new Algorithm instance using HmacSHA384.
|
static Algorithm |
HMAC512(byte[] secret)
Creates a new Algorithm instance using HmacSHA512.
|
static Algorithm |
HMAC512(java.lang.String secret)
Creates a new Algorithm instance using HmacSHA512.
|
static Algorithm |
none() |
static Algorithm |
RSA256(java.security.interfaces.RSAKey key)
Deprecated.
|
static Algorithm |
RSA256(RSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA256withRSA.
|
static Algorithm |
RSA256(java.security.interfaces.RSAPublicKey publicKey,
java.security.interfaces.RSAPrivateKey privateKey)
Creates a new Algorithm instance using SHA256withRSA.
|
static Algorithm |
RSA384(java.security.interfaces.RSAKey key)
Deprecated.
|
static Algorithm |
RSA384(RSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA384withRSA.
|
static Algorithm |
RSA384(java.security.interfaces.RSAPublicKey publicKey,
java.security.interfaces.RSAPrivateKey privateKey)
Creates a new Algorithm instance using SHA384withRSA.
|
static Algorithm |
RSA512(java.security.interfaces.RSAKey key)
Deprecated.
|
static Algorithm |
RSA512(RSAKeyProvider keyProvider)
Creates a new Algorithm instance using SHA512withRSA.
|
static Algorithm |
RSA512(java.security.interfaces.RSAPublicKey publicKey,
java.security.interfaces.RSAPrivateKey privateKey)
Creates a new Algorithm instance using SHA512withRSA.
|
abstract byte[] |
sign(byte[] contentBytes)
Sign the given content using this Algorithm instance.
|
java.lang.String |
toString() |
abstract void |
verify(DecodedJWT jwt)
Verify the given token using this Algorithm instance.
|
protected Algorithm(java.lang.String name, java.lang.String description)
public static Algorithm RSA256(RSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm RSA256(java.security.interfaces.RSAPublicKey publicKey, java.security.interfaces.RSAPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if both provided Keys are null.@Deprecated public static Algorithm RSA256(java.security.interfaces.RSAKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm RSA384(RSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm RSA384(java.security.interfaces.RSAPublicKey publicKey, java.security.interfaces.RSAPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if both provided Keys are null.@Deprecated public static Algorithm RSA384(java.security.interfaces.RSAKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm RSA512(RSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm RSA512(java.security.interfaces.RSAPublicKey publicKey, java.security.interfaces.RSAPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if both provided Keys are null.@Deprecated public static Algorithm RSA512(java.security.interfaces.RSAKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm HMAC256(java.lang.String secret) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
secret
- the secret to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.java.io.UnsupportedEncodingException
- if the current Java platform implementation doesn't support the UTF-8 character encoding.public static Algorithm HMAC384(java.lang.String secret) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
secret
- the secret to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.java.io.UnsupportedEncodingException
- if the current Java platform implementation doesn't support the UTF-8 character encoding.public static Algorithm HMAC512(java.lang.String secret) throws java.lang.IllegalArgumentException, java.io.UnsupportedEncodingException
secret
- the secret to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.java.io.UnsupportedEncodingException
- if the current Java platform implementation doesn't support the UTF-8 character encoding.public static Algorithm HMAC256(byte[] secret) throws java.lang.IllegalArgumentException
secret
- the secret bytes to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.public static Algorithm HMAC384(byte[] secret) throws java.lang.IllegalArgumentException
secret
- the secret bytes to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.public static Algorithm HMAC512(byte[] secret) throws java.lang.IllegalArgumentException
secret
- the secret bytes to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Secret is null.public static Algorithm ECDSA256(ECDSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm ECDSA256(java.security.interfaces.ECPublicKey publicKey, java.security.interfaces.ECPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.@Deprecated public static Algorithm ECDSA256(java.security.interfaces.ECKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm ECDSA384(ECDSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm ECDSA384(java.security.interfaces.ECPublicKey publicKey, java.security.interfaces.ECPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.@Deprecated public static Algorithm ECDSA384(java.security.interfaces.ECKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm ECDSA512(ECDSAKeyProvider keyProvider) throws java.lang.IllegalArgumentException
keyProvider
- the provider of the Public Key and Private Key for the verify and signing instance.java.lang.IllegalArgumentException
- if the Key Provider is null.public static Algorithm ECDSA512(java.security.interfaces.ECPublicKey publicKey, java.security.interfaces.ECPrivateKey privateKey) throws java.lang.IllegalArgumentException
publicKey
- the key to use in the verify instance.privateKey
- the key to use in the signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.@Deprecated public static Algorithm ECDSA512(java.security.interfaces.ECKey key) throws java.lang.IllegalArgumentException
key
- the key to use in the verify or signing instance.java.lang.IllegalArgumentException
- if the provided Key is null.public static Algorithm none()
public java.lang.String getSigningKeyId()
public java.lang.String getName()
public java.lang.String toString()
toString
in class java.lang.Object
public abstract void verify(DecodedJWT jwt) throws SignatureVerificationException
jwt
- the already decoded JWT that it's going to be verified.SignatureVerificationException
- if the Token's Signature is invalid, meaning that it doesn't match the signatureBytes, or if the Key is invalid.public abstract byte[] sign(byte[] contentBytes) throws SignatureGenerationException
contentBytes
- an array of bytes representing the base64 encoded content to be verified against the signature.SignatureGenerationException
- if the Key is invalid.