Package com.nimbusds.jose.crypto.impl
Class MACProvider
java.lang.Object
com.nimbusds.jose.crypto.impl.BaseJWSProvider
com.nimbusds.jose.crypto.impl.MACProvider
- All Implemented Interfaces:
JCAAware<JCAContext>
,JOSEProvider
,JWSProvider
- Direct Known Subclasses:
MACSigner
,MACVerifier
The base abstract class for Message Authentication Code (MAC) signers and
verifiers of
JWS objects
.
Supports the following algorithms:
- Version:
- 2024-10-28
- Author:
- Vladimir Dzhuvinov, Ulrich Winter
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Set<JWSAlgorithm>
The supported JWS algorithms by the MAC provider class. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
MACProvider
(byte[] secret) Creates a new Message Authentication (MAC) provider.protected
MACProvider
(SecretKey secretKey) Creates a new Message Authentication (MAC) provider. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Ensures the secret length satisfies the minimum required for the specified HMAC JWS algorithm.static Set<JWSAlgorithm>
getCompatibleAlgorithms
(int secretLength) Returns the compatible JWS HMAC algorithms for the specified secret length.protected static String
Gets the matching Java Cryptography Architecture (JCA) algorithm name for the specified HMAC-based JSON Web Algorithm (JWA).static int
Returns the minimal required secret length for the specified HMAC JWS algorithm.byte[]
Gets the secret bytes.Gets the secret key.Gets the secret as a UTF-8 encoded string.Methods inherited from class com.nimbusds.jose.crypto.impl.BaseJWSProvider
getJCAContext, supportedJWSAlgorithms
-
Field Details
-
SUPPORTED_ALGORITHMS
The supported JWS algorithms by the MAC provider class.
-
-
Constructor Details
-
MACProvider
Creates a new Message Authentication (MAC) provider.- Parameters:
secret
- The secret. Must be at least 256 bits long and notnull
.- Throws:
KeyLengthException
- If the secret length is shorter than the minimum 256-bit requirement.
-
MACProvider
Creates a new Message Authentication (MAC) provider.- Parameters:
secretKey
- The secret key. Must be at least 256 bits long and notnull
.S algorithms. Must not benull
.- Throws:
KeyLengthException
- If the secret length is shorter than the minimum 256-bit requirement.
-
-
Method Details
-
getCompatibleAlgorithms
Returns the compatible JWS HMAC algorithms for the specified secret length.- Parameters:
secretLength
- The secret length in bits. Must not be negative.- Returns:
- The compatible HMAC algorithms, empty set if the secret length is too short for any algorithm.
-
getMinRequiredSecretLength
Returns the minimal required secret length for the specified HMAC JWS algorithm.- Parameters:
alg
- The HMAC JWS algorithm. Must besupported
and notnull
.- Returns:
- The minimal required secret length, in bits.
- Throws:
JOSEException
- If the algorithm is not supported.
-
getJCAAlgorithmName
Gets the matching Java Cryptography Architecture (JCA) algorithm name for the specified HMAC-based JSON Web Algorithm (JWA).- Parameters:
alg
- The JSON Web Algorithm (JWA). Must be supported and notnull
.- Returns:
- The matching JCA algorithm name.
- Throws:
JOSEException
- If the algorithm is not supported.
-
getSecretKey
Gets the secret key.- Returns:
- The secret key.
-
getSecret
Gets the secret bytes.- Returns:
- The secret bytes,
null
if this provider was constructed with aSecretKey
that doesn't expose the key material.
-
getSecretString
Gets the secret as a UTF-8 encoded string.- Returns:
- The secret as a UTF-8 encoded string,
null
if this provider was constructed with aSecretKey
that doesn't expose the key material.
-
ensureSecretLengthSatisfiesAlgorithm
Ensures the secret length satisfies the minimum required for the specified HMAC JWS algorithm.- Parameters:
alg
- The HMAC JWS algorithm. Must besupported
and notnull
.- Throws:
JOSEException
- If the algorithm is not supported.KeyLengthException
- If the secret length is shorter than the minimum required.
-