Class UuidV3Generator
java.lang.Object
cloud.opencode.base.id.uuid.UuidV3Generator
UUID v3 Generator - Name-Based UUID using MD5
UUID v3生成器 - 基于名称的MD5 UUID
Generates deterministic UUIDs based on RFC 4122 version 3. The same namespace + name pair always produces the same UUID. Uses MD5 hashing of the namespace bytes concatenated with the name bytes.
基于RFC 4122版本3生成确定性UUID。相同的命名空间+名称组合始终产生相同的UUID。 使用命名空间字节与名称字节拼接后的MD5哈希值。
UUID v3 Structure | UUID v3结构:
Input = bytes(namespace_uuid) || bytes(name, UTF-8) Hash = MD5(Input) [16 bytes] hash[6] = (hash[6] & 0x0F) | 0x30 → version = 3 hash[8] = (hash[8] & 0x3F) | 0x80 → variant = 10xx UUID = UUID(msb=hash[0..7], lsb=hash[8..15])
Standard Namespaces | 标准命名空间 (RFC 4122):
NAMESPACE_DNS- 6ba7b810-9dad-11d1-80b4-00c04fd430c8NAMESPACE_URL- 6ba7b811-9dad-11d1-80b4-00c04fd430c8NAMESPACE_OID- 6ba7b812-9dad-11d1-80b4-00c04fd430c8NAMESPACE_X500- 6ba7b814-9dad-11d1-80b4-00c04fd430c8
Usage Examples | 使用示例:
UuidV3Generator gen = UuidV3Generator.create(UuidV3Generator.NAMESPACE_DNS);
// Deterministic: same input → same UUID
UUID uuid1 = gen.generate("example.com");
UUID uuid2 = gen.generate("example.com");
assert uuid1.equals(uuid2);
// Different names → different UUIDs
UUID a = gen.generate("foo.com");
UUID b = gen.generate("bar.com");
assert !a.equals(b);
Security | 安全性:
- Thread-safe: Yes (stateless after construction) - 线程安全: 是(构造后无状态)
- Deterministic: Yes - 确定性: 是
- Note: MD5 is not cryptographically secure; use UUID v5 (SHA-1) for security-sensitive cases. 注意: MD5并非密码学安全,安全敏感场景请使用UUID v5(SHA-1)。
- Since:
- JDK 25, opencode-base-id V1.0.4
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final UUIDDNS namespace UUID as defined in RFC 4122 | RFC 4122定义的DNS命名空间UUIDstatic final UUIDOID namespace UUID as defined in RFC 4122 | RFC 4122定义的OID命名空间UUIDstatic final UUIDURL namespace UUID as defined in RFC 4122 | RFC 4122定义的URL命名空间UUIDstatic final UUIDX.500 namespace UUID as defined in RFC 4122 | RFC 4122定义的X.500命名空间UUID -
Method Summary
Modifier and TypeMethodDescriptionstatic UuidV3GeneratorCreates a UUID v3 generator for the given namespace 为给定命名空间创建UUID v3生成器Generates a deterministic UUID v3 for the given name 为给定名称生成确定性UUID v3generateSimple(String name) Generates a simple UUID v3 string (no hyphens) for the given name 为给定名称生成简化UUID v3字符串(无连字符)generateStr(String name) Generates a UUID v3 string for the given name 为给定名称生成UUID v3字符串Returns the namespace used by this generator 返回此生成器使用的命名空间getType()Returns the generator type name 返回生成器类型名称
-
Field Details
-
NAMESPACE_DNS
DNS namespace UUID as defined in RFC 4122 | RFC 4122定义的DNS命名空间UUID -
NAMESPACE_URL
URL namespace UUID as defined in RFC 4122 | RFC 4122定义的URL命名空间UUID -
NAMESPACE_OID
OID namespace UUID as defined in RFC 4122 | RFC 4122定义的OID命名空间UUID -
NAMESPACE_X500
X.500 namespace UUID as defined in RFC 4122 | RFC 4122定义的X.500命名空间UUID
-
-
Method Details
-
create
Creates a UUID v3 generator for the given namespace 为给定命名空间创建UUID v3生成器- Parameters:
namespace- the namespace UUID | 命名空间UUID- Returns:
- generator | 生成器
- Throws:
IllegalArgumentException- if namespace is null | 命名空间为null时抛出
-
generate
Generates a deterministic UUID v3 for the given name 为给定名称生成确定性UUID v3Examples | 示例:
create(NAMESPACE_DNS).generate("python.org") → 6fa459ea-ee8a-3ca4-894e-db77e160355e create(NAMESPACE_DNS).generate("example.com") → always the same UUIDPerformance | 性能:
Time: O(n) where n = name length, Space: O(n)
- Parameters:
name- the name to hash | 要哈希的名称- Returns:
- deterministic UUID v3 | 确定性UUID v3
- Throws:
IllegalArgumentException- if name is null | 名称为null时抛出
-
generateStr
-
generateSimple
-
getNamespace
Returns the namespace used by this generator 返回此生成器使用的命名空间- Returns:
- namespace UUID | 命名空间UUID
-
getType
-