Package io.github.connellite.util
Class UuidGenerators
java.lang.Object
io.github.connellite.util.UuidGenerators
Cryptographically strong
UUID generators for versions 1 through 7 (RFC 4122 and RFC 9562).
Time-based generators follow the timestamp, clock-sequence, and node semantics used by uuid-creator: millisecond clock plus an internal 0–9,999 counter to simulate 100-ns resolution (RFC 4122 §4.2.1.2), a stable multicast node id, and a clock sequence that advances when the timestamp repeats.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDCE local domain: POSIX GID (1).static final intDCE local domain: organization/site-defined (2).static final intDCE local domain: POSIX UID (0).static final UUIDRFC 4122 DNS namespace (6ba7b810-9dad-11d1-80b4-00c04fd430c8).static final UUIDRFC 4122 OID namespace (6ba7b812-9dad-11d1-80b4-00c04fd430c8).static final UUIDRFC 4122 URL namespace (6ba7b811-9dad-11d1-80b4-00c04fd430c8).static final UUIDRFC 4122 X.500 DN namespace (6ba7b814-9dad-11d1-80b4-00c04fd430c8).static final UUIDMax UUID (RFC 9562):ffffffff-ffff-ffff-ffff-ffffffffffff— all bits one.static final UUIDNil UUID (RFC 9562):00000000-0000-0000-0000-000000000000— all bits zero. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic UUIDVersion 1: time-based UUID (RFC 4122 §4.2).static UUIDVersion 2: DCE Security time-based UUID (RFC 4122 §4.1.2).static UUIDgenerateVersion2(int localDomain, long localIdentifier) Version 2: DCE Security time-based UUID (DCE 1.1; RFC 4122 §4.1.3, RFC 9562 §5.2).static UUIDgenerateVersion3(UUID namespace, byte[] name) Version 3: name-based UUID using MD5 (RFC 4122 §4.3).static UUIDgenerateVersion3(UUID namespace, String name) Version 3: name-based UUID using MD5 (RFC 4122 §4.3).static UUIDVersion 4: random UUID (RFC 4122 §4.4).static UUIDgenerateVersion5(UUID namespace, byte[] name) Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).static UUIDgenerateVersion5(UUID namespace, String name) Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).static UUIDVersion 6: time-ordered UUID (RFC 9562 §5.6).static UUIDVersion 7: Unix-epoch time-ordered UUID (RFC 9562 §5.7).
-
Field Details
-
NAMESPACE_DNS
RFC 4122 DNS namespace (6ba7b810-9dad-11d1-80b4-00c04fd430c8). -
NAMESPACE_URL
RFC 4122 URL namespace (6ba7b811-9dad-11d1-80b4-00c04fd430c8). -
NAMESPACE_OID
RFC 4122 OID namespace (6ba7b812-9dad-11d1-80b4-00c04fd430c8). -
NAMESPACE_X500
RFC 4122 X.500 DN namespace (6ba7b814-9dad-11d1-80b4-00c04fd430c8). -
UUID_NIL
Nil UUID (RFC 9562):00000000-0000-0000-0000-000000000000— all bits zero. -
UUID_MAX
Max UUID (RFC 9562):ffffffff-ffff-ffff-ffff-ffffffffffff— all bits one. -
LOCAL_DOMAIN_PERSON
public static final int LOCAL_DOMAIN_PERSONDCE local domain: POSIX UID (0).- See Also:
-
LOCAL_DOMAIN_GROUP
public static final int LOCAL_DOMAIN_GROUPDCE local domain: POSIX GID (1).- See Also:
-
LOCAL_DOMAIN_ORG
public static final int LOCAL_DOMAIN_ORGDCE local domain: organization/site-defined (2).- See Also:
-
-
Constructor Details
-
UuidGenerators
public UuidGenerators()
-
-
Method Details
-
generateVersion1
Version 1: time-based UUID (RFC 4122 §4.2).- Returns:
- a new version-1 UUID
-
generateVersion2
Version 2: DCE Security time-based UUID (RFC 4122 §4.1.2).Builds a version-1 UUID, then embeds the local domain and identifier (uuid-creator
DceSecurityFactory).- Returns:
- a new version-2 UUID with a random 32-bit local identifier and
LOCAL_DOMAIN_PERSON
-
generateVersion2
Version 2: DCE Security time-based UUID (DCE 1.1; RFC 4122 §4.1.3, RFC 9562 §5.2).DCE 1.1 Authentication and Security Services registers only
LOCAL_DOMAIN_PERSON,LOCAL_DOMAIN_GROUP, andLOCAL_DOMAIN_ORG.- Parameters:
localDomain- registered DCE local domain (0,1, or2)localIdentifier- 32-bit identifier meaningful inlocalDomain- Returns:
- a new version-2 UUID
- Throws:
IllegalArgumentException- iflocalDomainis not a registered DCE domain
-
generateVersion3
Version 3: name-based UUID using MD5 (RFC 4122 §4.3).- Parameters:
namespace- well-known or application namespace UUID; must not benullname- name bytes withinnamespace; must not benull- Returns:
- deterministic version-3 UUID for the given namespace and name
- Throws:
NoSuchAlgorithmException- if MD5 is not available
-
generateVersion3
Version 3: name-based UUID using MD5 (RFC 4122 §4.3).- Parameters:
namespace- well-known or application namespace UUID; must not benullname- UTF-8 name withinnamespace; must not benull- Returns:
- deterministic version-3 UUID for the given namespace and name
- Throws:
NoSuchAlgorithmException- if MD5 is not available
-
generateVersion4
Version 4: random UUID (RFC 4122 §4.4).- Returns:
- a new version-4 UUID
-
generateVersion5
Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).- Parameters:
namespace- well-known or application namespace UUID; must not benullname- name bytes withinnamespace; must not benull- Returns:
- deterministic version-5 UUID for the given namespace and name
- Throws:
NoSuchAlgorithmException- if SHA-1 is not available
-
generateVersion5
Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).- Parameters:
namespace- well-known or application namespace UUID; must not benullname- UTF-8 name withinnamespace; must not benull- Returns:
- deterministic version-5 UUID for the given namespace and name
- Throws:
NoSuchAlgorithmException- if SHA-1 is not available
-
generateVersion6
Version 6: time-ordered UUID (RFC 9562 §5.6).- Returns:
- a new version-6 UUID
-
generateVersion7
Version 7: Unix-epoch time-ordered UUID (RFC 9562 §5.7).Uses millisecond
unix_ts_ms, injects microseconds intorand_awhen the system clock allows, and incrementsrand_bwhen the millisecond repeats (uuid-creatorTimeOrderedEpochFactory).- Returns:
- a new version-7 UUID
-