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
public class IdentifierWithHMAC extends BaseIdentifier
Identifier with Hash-based (SHA-256) Message Authentication Code (HMAC).
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_BYTE_LENGTH
The default byte length of generated identifiers.-
Fields inherited from class com.nimbusds.common.id.BaseIdentifier
SECURE_RANDOM
-
-
Constructor Summary
Constructors Constructor Description IdentifierWithHMAC(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object object)
OverridesObject.equals()
.static com.nimbusds.jose.util.Base64URL[]
parse(String value)
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 Detail
-
DEFAULT_BYTE_LENGTH
public static final int DEFAULT_BYTE_LENGTH
The default byte length of generated identifiers.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IdentifierWithHMAC
public IdentifierWithHMAC(byte[] value, SecretKey hmacKey)
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
public IdentifierWithHMAC(SecretKey hmacKey)
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 Detail
-
equals
public boolean equals(Object object)
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
public static com.nimbusds.jose.util.Base64URL[] parseUnchecked(String value)
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.
-
-