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(java.security.interfaces.ECKey key)
Creates a new Algorithm instance using SHA256withECDSA.
|
static Algorithm |
ECDSA384(java.security.interfaces.ECKey key)
Creates a new Algorithm instance using SHA384withECDSA.
|
static Algorithm |
ECDSA512(java.security.interfaces.ECKey key)
Creates a new Algorithm instance using SHA512withECDSA.
|
java.lang.String |
getName()
Getter for the name of this Algorithm, as defined in the JWT Standard.
|
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)
Creates a new Algorithm instance using SHA256withRSA.
|
static Algorithm |
RSA384(java.security.interfaces.RSAKey key)
Creates a new Algorithm instance using SHA384withRSA.
|
static Algorithm |
RSA512(java.security.interfaces.RSAKey key)
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(byte[] contentBytes,
byte[] signatureBytes)
Verify the given content using this Algorithm instance.
|
protected Algorithm(java.lang.String name, java.lang.String description)
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 provided Key is null.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(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(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(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(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 getName()
public java.lang.String toString()
toString
in class java.lang.Object
public abstract void verify(byte[] contentBytes, byte[] signatureBytes) throws SignatureVerificationException
contentBytes
- an array of bytes representing the base64 encoded content to be verified against the signature.signatureBytes
- an array of bytes representing the base64 encoded signature to compare the content against.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.