-
Notifications
You must be signed in to change notification settings - Fork 44
1.5. UUIDv5
Fabio Lima edited this page Dec 20, 2024
·
5 revisions
💡 HINT
What are UUIDs?: https://playfulprogramming.com/posts/what-are-uuids#UUIDv3and5
Creating a Name-based UUID:
String name = "https://github.com/";
UUID uuid = UuidCreator.getNameBasedSha1(UuidNamespace.NAMESPACE_URL, name);
List of predefined namespaces:
-
UuidNamespace.NAMESPACE_DNS
: Name string is a fully-qualified domain name; -
UuidNamespace.NAMESPACE_URL
: Name string is a URL; -
UuidNamespace.NAMESPACE_ISO_OID
: Name string is an ISO Object ID; -
UuidNamespace.NAMESPACE_X500_DN
: Name string is an X.500 Distinguished Name (in DER or a text output format).
A name-based factory that uses a unique namespace defined for the application:
// a random unique namespace for the application
UUID namespace = UUID.fromString("b86919b5-d2b1-455e-8ef5-b752f3fa8416");
// a name-based factory that uses the unique namespace
NameBasedSha1Factory factory = new NameBasedSha1Factory(namespace);
// use the factory as many times as needed
UUID uuid = factory.create("This is a test string");