UUID v2 Generator
लोकल डोमेन और ID के साथ DCE Security UUID v2 जनरेट करें
UUID v2 क्या है?
UUID v2 DCE Security UUID version है, Distributed Computing Environment (DCE) specification के हिस्से के रूप में standardised और RFC 4122 में referenced। यह UUID v1 को POSIX user या group identifier (UID/GID) को timestamp field में embed करके extend करता है।
Structure UUID v1 के समान है, लेकिन 32-bit time_low field को 32-bit local identifier (जैसे POSIX UID) से replace किया गया है और एक 1-byte local_domain field identify करता है कि यह किस प्रकार का local ID है।
UUID v2 modern software में extremely rare है। ज़्यादातर developers को कभी एक generate करने की ज़रूरत नहीं पड़ेगी। यह page format को document करती है completeness के लिए और legacy systems में encountered UUID v2 values decode करने में aid के लिए।
UUID v2 Structure
UUID v2 का same 128-bit, hyphenated format है। Fields UUID v1 से निम्नानुसार differ करते हैं:
| Field | Bits | Purpose |
|---|---|---|
| local_id | 32 | <code>local_id</code> — 32-bit local domain identifier (जैसे <code>/etc/passwd</code> से POSIX UID), UUID v1 का time_low field replace करता है |
| time_mid | 16 | <code>time_mid</code> — truncated UUID v1 timestamp के middle 16 bits |
| time_hi+version | 16 | <code>time_hi_and_version</code> — version nibble <code>2</code> set के साथ top 12 timestamp bits |
| variant+clock_hi | 8 | <code>clock_seq_hi_and_reserved</code> — variant bits plus clock sequence का high portion |
| local_domain | 8 | <code>local_domain</code> — domain identifier: <code>0</code> = POSIX User (UID), <code>1</code> = POSIX Group (GID), <code>2</code> = Organization |
| node | 48 | <code>node</code> — generating host का 48-bit MAC address |
Example: 000003e8-92e0-21ef-8000-325096b39f47 — local_id 0x000003e8 = UID 1000, local_domain 0x00 = POSIX User
Local Domain Values
local_domain byte UUID में embedded local identifier का type specify करता है:
Domain values DCE specification द्वारा defined हैं। Values 3–255 reserved हैं। Practice में, केवल domain 0 (Person/UID) real-world UUID v2 values में commonly encountered है।
UUID v2 Rarely क्यों Use किया जाता है
तीन characteristics UUID v2 को ज़्यादातर modern applications के लिए impractical बनाते हैं:
Coarse Timestamp Resolution
Timestamp 28 bits तक truncated है (approximately 7.2-minute granularity)। उस window में, same local_id और domain के साथ same host पर generate किए गए UUIDs unique नहीं हैं।
No Standard Library Support
UUID v1 और v4 के विपरीत, UUID v2 ज़्यादातर UUID libraries द्वारा supported नहीं है। uuid npm package, Python's uuid module, और Java's java.util.UUID सभी v2 omit करते हैं।
POSIX-specific Semantics
Local domain concept (UID/GID) inherently POSIX-specific है और Windows, embedded systems, या cloud environments में meaningfully translate नहीं होता।
Historical Context
UUID v2 को Open Software Foundation के Distributed Computing Environment (DCE/RPC) के हिस्से के रूप में 1990s के early में define किया गया था।
DCE security model एक homogeneous POSIX environment assume करता था जहाँ हर node shared UID/GID namespace में participate करता था।
- Internet ने homogeneous POSIX environments से heterogeneous cloud architectures की ओर move किया
- Modern authentication identifiers में embedded UIDs के बजाय tokens (JWT, OAuth) use करती है
- UUID v4 (fully random) और UUID v7 (time-ordered) unique identifiers के practical use cases cover करते हैं
- DCE/RPC itself widespread use से बाहर हो गया
RFC 4122 (2005) ने UUID v2 को DCE specification के reference द्वारा include किया, लेकिन detailed generation algorithm deliberately omit किया।
RFC 9562 (2024) ने UUID v2 को historical completeness के लिए retain किया।
UUID v2 vs UUID v1
UUID v2 UUID v1 से derived है। यहाँ वे कैसे compare करते हैं:
| Aspect | UUID v1 | UUID v2 |
|---|---|---|
| Timestamp bits | 60 bits (~100ns precision) | 28 bits (~7.2-minute precision) |
| Local identifier | कोई नहीं | 32-bit POSIX UID/GID |
| Local domain | Present नहीं | 0=UID, 1=GID, 2=Org |
| Node field | MAC address | MAC address |
| Library support | Widely supported | Rarely supported |
| Standard | RFC 4122 / RFC 9562 | DCE spec (RFC 4122 द्वारा referenced) |
| Practical use | Legacy timestamp-ordered IDs (Cassandra) | केवल DCE Security contexts |
UUID v2 general-purpose use के लिए UUID v1 पर कुछ offer नहीं करता, और ज़्यादातर respects में strictly worse है। नए development के लिए UUID v2 choose करने का कोई reason नहीं है।
Code Examples
UUID v2 का standard libraries में कोई native support नहीं है। निम्नलिखित examples UUID v2 values के साथ काम करने का तरीका दिखाते हैं:
Python — manual implementation
import uuid, struct, time
def uuid_v2(local_id: int, local_domain: int = 0) -> str:
"""
Generate a DCE Security UUID (v2).
local_domain: 0 = POSIX UID, 1 = POSIX GID, 2 = Org
local_id: 32-bit unsigned integer (e.g. os.getuid())
"""
# Get a v1 UUID for the time and node fields
v1 = uuid.uuid1()
fields = list(v1.fields) # [time_low, time_mid, time_hi_version, clock_seq_hi_variant, clock_seq_low, node]
# Replace time_low with local_id
fields[0] = local_id & 0xFFFFFFFF
# Replace version nibble: clear lower 12 bits of time_hi, set version 2
fields[2] = (fields[2] & 0x0FFF) | 0x2000
# Replace clock_seq_low with local_domain
fields[4] = local_domain & 0xFF
return str(uuid.UUID(fields=tuple(fields)))
import os
print(uuid_v2(os.getuid(), local_domain=0)) # POSIX UID
print(uuid_v2(os.getgid(), local_domain=1)) # POSIX GID
Go — note
// The standard "github.com/google/uuid" package does NOT support v2. // You would need to implement it manually, similar to the Python example above. // Most Go developers use v4 or v7 for new projects. import "github.com/google/uuid" v4 := uuid.New() // v4 — recommended for most use cases v7, _ := uuid.NewV7() // v7 — time-ordered, ideal for database primary keys
JavaScript — extract fields
Existing UUID v2 string से local_id और domain extract करने के लिए:
// Extracting fields from a UUID v2 string
const uuidStr = '000003e8-1234-2abc-8200-a1b2c3d4e5f6'
// ^^^^^^^^ ^^^^ ^ ^^
// local_id ver variant+clockSeqHi
// ^^ = local_domain (00 = POSIX UID)
const parts = uuidStr.split('-')
const localId = parseInt(parts[0], 16) // → 1000 (0x3e8)
const version = parseInt(parts[2][0], 16) // → 2
const localDomain = parseInt(parts[3].slice(2), 16) // low byte of octet pair
const DOMAIN_NAMES = ['POSIX UID', 'POSIX GID', 'Org']
console.log(`Local ID: ${localId}`) // Local ID: 1000
console.log(`Version: ${version}`) // Version: 2
console.log(`Domain: ${DOMAIN_NAMES[localDomain]}`) // Domain: POSIX UID
google/uuid Go package UUID v2 generation support करता है uuid.NewDCEGroup() और uuid.NewDCEPerson() के माध्यम से।