Package com.nimbusds.jose.crypto.impl
Class HMAC
java.lang.Object
com.nimbusds.jose.crypto.impl.HMAC
Static methods for Hash-based Message Authentication Codes (HMAC). This
class is thread-safe.
- Version:
- 2023-09-14
- Author:
- Axel Nennker, Vladimir Dzhuvinov, Ulrich Winter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
Deprecated.static byte[]
Computes a Hash-based Message Authentication Code (HMAC) for the specified secret key and message.static byte[]
Computes a Hash-based Message Authentication Code (HMAC) for the specified secret key and message.static Mac
getInitMac
(String alg, SecretKey secretKey, Provider provider) Gets an initialised Message Authentication Code (MAC) service instance.static Mac
getInitMac
(SecretKey secretKey, Provider provider) Gets an initialised Message Authentication Code (MAC) service instance.
-
Constructor Details
-
HMAC
public HMAC()
-
-
Method Details
-
getInitMac
Gets an initialised Message Authentication Code (MAC) service instance.- Parameters:
secretKey
- The secret key, with the appropriate HMAC algorithm. Must not benull
.provider
- The JCA provider,null
to use the default.- Returns:
- The MAC service instance.
- Throws:
JOSEException
- If the algorithm is not supported or the MAC secret key is invalid.
-
getInitMac
public static Mac getInitMac(String alg, SecretKey secretKey, Provider provider) throws JOSEException Gets an initialised Message Authentication Code (MAC) service instance.- Parameters:
alg
- The Java Cryptography Architecture (JCA) HMAC algorithm name. Must not benull
.secretKey
- The secret key. Its algorithm name is ignored. Must not benull
.provider
- The JCA provider,null
to use the default.- Returns:
- The MAC service instance.
- Throws:
JOSEException
- If the algorithm is not supported or the MAC secret key is invalid.
-
compute
@Deprecated public static byte[] compute(String alg, byte[] secret, byte[] message, Provider provider) throws JOSEException Deprecated.Computes a Hash-based Message Authentication Code (HMAC) for the specified secret and message.- Parameters:
alg
- The Java Cryptography Architecture (JCA) HMAC algorithm name. Must not benull
.secret
- The secret. Must not benull
.message
- The message. Must not benull
.provider
- The JCA provider,null
to use the default.- Returns:
- The computed HMAC.
- Throws:
JOSEException
- If the algorithm is not supported or the MAC secret key is invalid.
-
compute
public static byte[] compute(String alg, SecretKey secretKey, byte[] message, Provider provider) throws JOSEException Computes a Hash-based Message Authentication Code (HMAC) for the specified secret key and message.- Parameters:
alg
- The Java Cryptography Architecture (JCA) HMAC algorithm name. Must not benull
.secretKey
- The secret key. Its algorithm name is ignored. Must not benull
.message
- The message. Must not benull
.provider
- The JCA provider,null
to use the default.- Returns:
- The computed HMAC.
- Throws:
JOSEException
- If the algorithm is not supported or the MAC secret key is invalid.
-
compute
public static byte[] compute(SecretKey secretKey, byte[] message, Provider provider) throws JOSEException Computes a Hash-based Message Authentication Code (HMAC) for the specified secret key and message.- Parameters:
secretKey
- The secret key, with the appropriate HMAC algorithm. Must not benull
.message
- The message. Must not benull
.provider
- The JCA provider, ornull
to use the default one.- Returns:
- A MAC service instance.
- Throws:
JOSEException
- If the algorithm is not supported or the MAC secret key is invalid.
-