Package com.helger.base.uuid
Class UUID5Helper
java.lang.Object
com.helger.base.uuid.UUID5Helper
This class contains static methods that leverage
UUID and
MessageDigest to create version-5 UUIDs with full namespace support.
The UUID class provided by java.util is suitable as a datatype for UUIDs of any version, but lacks methods for creating version 5 (SHA-1 based) UUIDs. Its implementation of version 3 (MD5 based) UUIDs also lacks build-in namespace support.
This class was inspired by https://github.com/rootsdev/polygenea/blob/master/java/src/org/rootsdev/polygenea/UUID5.java from Luther Tychonievich
- Since:
- v12.1.3
- Author:
- Philip Helger
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull UUIDfromBytes(byte @NonNull [] aNameBytes) Similar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5)static @NonNull UUIDSimilar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5) and uses a namespacestatic @NonNull UUIDSimilar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5)static @NonNull UUIDSimilar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5) and uses a namespace
-
Method Details
-
fromBytes
Similar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5)- Parameters:
aNameBytes- The bytes to use as the "name" of this hash- Returns:
- the UUID object and never
null.
-
fromBytes
Similar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5) and uses a namespace- Parameters:
aNamespace- The namespace to use for this UUID. Ifnull, uses 00000000-0000-0000-0000-000000000000aNameBytes- The bytes to use as the "name" of this hash. May not benull.- Returns:
- the UUID object and never
null.
-
fromUTF8
Similar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5)- Parameters:
sName- The string to be encoded in utf-8 to get the bytes to hash. May not benull.- Returns:
- the UUID object
-
fromUTF8
Similar to UUID.nameUUIDFromBytes, but does version 5 (sha-1) not version 3 (md5) and uses a namespace- Parameters:
aNamespace- The namespace to use for this UUID. Ifnull, uses 00000000-0000-0000-0000-000000000000sName- The string to be encoded in utf-8 to get the bytes to hash. May not benull.- Returns:
- the UUID object
-