Class UuidGenerators

java.lang.Object
io.github.connellite.util.UuidGenerators

public class UuidGenerators extends Object
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 Details

    • NAMESPACE_DNS

      public static final UUID NAMESPACE_DNS
      RFC 4122 DNS namespace (6ba7b810-9dad-11d1-80b4-00c04fd430c8).
    • NAMESPACE_URL

      public static final UUID NAMESPACE_URL
      RFC 4122 URL namespace (6ba7b811-9dad-11d1-80b4-00c04fd430c8).
    • NAMESPACE_OID

      public static final UUID NAMESPACE_OID
      RFC 4122 OID namespace (6ba7b812-9dad-11d1-80b4-00c04fd430c8).
    • NAMESPACE_X500

      public static final UUID NAMESPACE_X500
      RFC 4122 X.500 DN namespace (6ba7b814-9dad-11d1-80b4-00c04fd430c8).
    • UUID_NIL

      public static final UUID UUID_NIL
      Nil UUID (RFC 9562): 00000000-0000-0000-0000-000000000000 — all bits zero.
    • UUID_MAX

      public static final UUID UUID_MAX
      Max UUID (RFC 9562): ffffffff-ffff-ffff-ffff-ffffffffffff — all bits one.
    • LOCAL_DOMAIN_PERSON

      public static final int LOCAL_DOMAIN_PERSON
      DCE local domain: POSIX UID (0).
      See Also:
    • LOCAL_DOMAIN_GROUP

      public static final int LOCAL_DOMAIN_GROUP
      DCE local domain: POSIX GID (1).
      See Also:
    • LOCAL_DOMAIN_ORG

      public static final int LOCAL_DOMAIN_ORG
      DCE local domain: organization/site-defined (2).
      See Also:
  • Constructor Details

    • UuidGenerators

      public UuidGenerators()
  • Method Details

    • generateVersion1

      public static UUID generateVersion1()
      Version 1: time-based UUID (RFC 4122 §4.2).
      Returns:
      a new version-1 UUID
    • generateVersion2

      public static 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

      public static UUID generateVersion2(int localDomain, long localIdentifier)
      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, and LOCAL_DOMAIN_ORG.

      Parameters:
      localDomain - registered DCE local domain (0, 1, or 2)
      localIdentifier - 32-bit identifier meaningful in localDomain
      Returns:
      a new version-2 UUID
      Throws:
      IllegalArgumentException - if localDomain is not a registered DCE domain
    • generateVersion3

      public static UUID generateVersion3(UUID namespace, byte[] name) throws NoSuchAlgorithmException
      Version 3: name-based UUID using MD5 (RFC 4122 §4.3).
      Parameters:
      namespace - well-known or application namespace UUID; must not be null
      name - name bytes within namespace; must not be null
      Returns:
      deterministic version-3 UUID for the given namespace and name
      Throws:
      NoSuchAlgorithmException - if MD5 is not available
    • generateVersion3

      public static UUID generateVersion3(UUID namespace, String name) throws NoSuchAlgorithmException
      Version 3: name-based UUID using MD5 (RFC 4122 §4.3).
      Parameters:
      namespace - well-known or application namespace UUID; must not be null
      name - UTF-8 name within namespace; must not be null
      Returns:
      deterministic version-3 UUID for the given namespace and name
      Throws:
      NoSuchAlgorithmException - if MD5 is not available
    • generateVersion4

      public static UUID generateVersion4()
      Version 4: random UUID (RFC 4122 §4.4).
      Returns:
      a new version-4 UUID
    • generateVersion5

      public static UUID generateVersion5(UUID namespace, byte[] name) throws NoSuchAlgorithmException
      Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).
      Parameters:
      namespace - well-known or application namespace UUID; must not be null
      name - name bytes within namespace; must not be null
      Returns:
      deterministic version-5 UUID for the given namespace and name
      Throws:
      NoSuchAlgorithmException - if SHA-1 is not available
    • generateVersion5

      public static UUID generateVersion5(UUID namespace, String name) throws NoSuchAlgorithmException
      Version 5: name-based UUID using SHA-1 (RFC 4122 §4.5).
      Parameters:
      namespace - well-known or application namespace UUID; must not be null
      name - UTF-8 name within namespace; must not be null
      Returns:
      deterministic version-5 UUID for the given namespace and name
      Throws:
      NoSuchAlgorithmException - if SHA-1 is not available
    • generateVersion6

      public static UUID generateVersion6()
      Version 6: time-ordered UUID (RFC 9562 §5.6).
      Returns:
      a new version-6 UUID
    • generateVersion7

      public static UUID generateVersion7()
      Version 7: Unix-epoch time-ordered UUID (RFC 9562 §5.7).

      Uses millisecond unix_ts_ms, injects microseconds into rand_a when the system clock allows, and increments rand_b when the millisecond repeats (uuid-creator TimeOrderedEpochFactory).

      Returns:
      a new version-7 UUID