@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, getSecretString
getJCAContext, supportedJWSAlgorithms
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
supportedJWSAlgorithms
getJCAContext
public 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
JWSSigner
input
of a
JWS object
.sign
in interface JWSSigner
header
- 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 © 2020 Connect2id Ltd.. All rights reserved.