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 Details

  • Constructor Details

    • 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 or null.
      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 Details

    • equals

      public boolean equals(Object object)
      Description copied from class: BaseIdentifier
      Overrides Object.equals().
      Specified by:
      equals in class BaseIdentifier
      Parameters:
      object - The object to compare to.
      Returns:
      true if the objects have the same value, otherwise false.
    • parseAndValidate

      Parses and validates the specified identifier with HMAC protection.
      Parameters:
      value - The identifier value to parse and validate. Must not be null.
      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 be null.
      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 be null.
      Returns:
      The identifier parts.
      Throws:
      RuntimeException - If the identifier format is illegal.