java.lang.Object
edu.iu.IdGenerator
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 Summary
Modifier and TypeMethodDescriptionstatic String
Generates a new unique identifier.static void
Validates that a new unique identifier was created by the same algorithm used in this utility, and has not expired.
-
Method Details
-
generateId
Generates a new unique identifier.- Returns:
- new unique identifier
-
verifyId
Validates that a new unique identifier was created by the same algorithm used in this utility, and has not expired.- Parameters:
id
- id to verifyttl
- millisecond time to live for determining the expiration time for the id; 0 for no expiration time
-