Module iu.util
Package edu.iu

Class IdGenerator

java.lang.Object
edu.iu.IdGenerator

public class IdGenerator extends Object
Provides a utility for generating short cryptographically secure unique identifiers.

Identifiers generated by this utility are smaller and less likely to collide than the random (v4) UUID values from UUID.randomUUID().

  • Generates 24 bytes of pseudorandom data, interposed with
    • The 4 byte seconds since epoch timestamp
    • The lower 3 bytes of a hash checksum seeded by the system timestamp
  • Uses a modified Base64 transform to convert to an id-safe 32 character string
    • Includes only upper and lower case letters, digits, hyphen and underline characters
    • May be verified as having been generated by the same algorithm, optionally with a millisecond time to live
  • Method Details

    • generateId

      public static String generateId()
      Generates a new unique identifier.
      Returns:
      new unique identifier
    • verifyId

      public static void verifyId(String id, long ttl)
      Validates that a new unique identifier was created by the same algorithm used in this utility, and has not expired.
      Parameters:
      id - id to verify
      ttl - millisecond time to live for determining the expiration time for the id; 0 for no expiration time