@ThreadSafe public class MACSigner extends MACProvider implements JWSSigner
JWS objects. Expects a secret key.
See RFC 7518 section 3.2 for more information.
This class is thread-safe.
Supports the following algorithms:
SUPPORTED_ALGORITHMS| Constructor and Description |
|---|
MACSigner(byte[] secret)
Creates a new Message Authentication (MAC) signer.
|
MACSigner(OctetSequenceKey jwk)
Creates a new Message Authentication (MAC) signer.
|
MACSigner(SecretKey secretKey)
Creates a new Message Authentication (MAC) signer.
|
MACSigner(String secretString)
Creates a new Message Authentication (MAC) signer.
|
| Modifier and Type | Method and Description |
|---|---|
static Set<JWSAlgorithm> |
getCompatibleAlgorithms(int secretLength)
Returns the compatible JWS HMAC algorithms for the specified secret
length.
|
static int |
getMinRequiredSecretLength(JWSAlgorithm alg)
Returns the minimal required secret length for the specified HMAC
JWS algorithm.
|
Base64URL |
sign(JWSHeader header,
byte[] signingInput)
Signs the specified
input of a
JWS object. |
getJCAAlgorithmName, getSecret, getSecretKey, getSecretStringgetJCAContext, supportedJWSAlgorithmsclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitsupportedJWSAlgorithmsgetJCAContextpublic MACSigner(byte[] secret) throws KeyLengthException
secret - The secret. Must be at least 256 bits long and not
null.KeyLengthException - If the secret length is shorter than the
minimum 256-bit requirement.public MACSigner(String secretString) throws KeyLengthException
secretString - The secret as a UTF-8 encoded string. Must be at
least 256 bits long and not null.KeyLengthException - If the secret length is shorter than the
minimum 256-bit requirement.public MACSigner(SecretKey secretKey) throws KeyLengthException
secretKey - The secret key. Must be at least 256 bits long and
not null.KeyLengthException - If the secret length is shorter than the
minimum 256-bit requirement.public MACSigner(OctetSequenceKey jwk) throws KeyLengthException
jwk - The secret as a JWK. Must be at least 256 bits long and
not null.KeyLengthException - If the secret length is shorter than the
minimum 256-bit requirement.public static int getMinRequiredSecretLength(JWSAlgorithm alg) throws JOSEException
alg - The HMAC JWS algorithm. Must be
supported and not
null.JOSEException - If the algorithm is not supported.public static Set<JWSAlgorithm> getCompatibleAlgorithms(int secretLength)
secretLength - The secret length in bits. Must not be negative.public Base64URL sign(JWSHeader header, byte[] signingInput) throws JOSEException
JWSSignerinput of a
JWS object.sign in interface JWSSignerheader - The JSON Web Signature (JWS) header. Must
specify a supported JWS algorithm and must not
be null.signingInput - The input to sign. Must not be null.JOSEException - If the JWS algorithm is not supported, if a
critical header parameter is not supported or
marked for deferral to the application, or if
signing failed for some other internal reason.Copyright © 2019 Connect2id Ltd.. All rights reserved.