Package com.nimbusds.common.id
Class IdentifierWithHMAC
java.lang.Object
com.nimbusds.common.id.BaseIdentifier
com.nimbusds.common.id.IdentifierWithHMAC
- All Implemented Interfaces:
Identifier
,Comparable<Identifier>
,net.minidev.json.JSONAware
Identifier with Hash-based (SHA-256) Message Authentication Code (HMAC).
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The default byte length of generated identifiers.Fields inherited from class com.nimbusds.common.id.BaseIdentifier
SECURE_RANDOM
-
Constructor Summary
ConstructorDescriptionIdentifierWithHMAC
(byte[] value, SecretKey hmacKey) Creates a new identifier protected with a SHA-256 based HMAC.IdentifierWithHMAC
(SecretKey hmacKey) Generates a new 128-bite secure random identifier and protects it with a SHA-256 based HMAC. -
Method Summary
Modifier and TypeMethodDescriptionboolean
OverridesObject.equals()
.static com.nimbusds.jose.util.Base64URL[]
Parses the specified identifier with HMAC protection.static IdentifierWithHMAC
parseAndValidate
(String value, SecretKey hmacKey) Parses and validates the specified identifier with HMAC protection.static com.nimbusds.jose.util.Base64URL[]
parseUnchecked
(String value) Parses the specified identifier with HMAC protection.Methods inherited from class com.nimbusds.common.id.BaseIdentifier
compareTo, hashCode, toJSONString, toString
-
Field Details
-
DEFAULT_BYTE_LENGTH
The default byte length of generated identifiers.- See Also:
-
-
Constructor Details
-
IdentifierWithHMAC
Creates a new identifier protected with a SHA-256 based HMAC.- Parameters:
value
- The identifier value. Must not empty ornull
.hmacKey
- The HMAC key. Must be at least 128 bits long.
-
IdentifierWithHMAC
Generates a new 128-bite secure random identifier and protects it with a SHA-256 based HMAC.- Parameters:
hmacKey
- The HMAC key. Must be at least 128 bits long.- Throws:
RuntimeException
- If HMAC computation failed.
-
-
Method Details
-
equals
Description copied from class:BaseIdentifier
OverridesObject.equals()
.- Specified by:
equals
in classBaseIdentifier
- Parameters:
object
- The object to compare to.- Returns:
true
if the objects have the same value, otherwisefalse
.
-
parseAndValidate
public static IdentifierWithHMAC parseAndValidate(String value, SecretKey hmacKey) throws InvalidIdentifierException Parses and validates the specified identifier with HMAC protection.- Parameters:
value
- The identifier value to parse and validate. Must not benull
.hmacKey
- The HMAC key. Must be at least 128 bits long.- Returns:
- The validated identifier.
- Throws:
InvalidIdentifierException
- If the identifier format is illegal or the HMAC is invalid.RuntimeException
- If HMAC computation failed.
-
parse
public static com.nimbusds.jose.util.Base64URL[] parse(String value) throws InvalidIdentifierException Parses the specified identifier with HMAC protection.- Parameters:
value
- The identifier value to parse and validate. Must not benull
.- Returns:
- The identifier parts.
- Throws:
InvalidIdentifierException
- If the identifier format is illegal.
-
parseUnchecked
Parses the specified identifier with HMAC protection.- Parameters:
value
- The identifier value to parse and validate. Must not benull
.- Returns:
- The identifier parts.
- Throws:
RuntimeException
- If the identifier format is illegal.
-