Skip to content

1.5. UUIDv5

Fabio Lima edited this page Dec 20, 2024 · 5 revisions

Name-based UUID with SHA-1 hashing

💡 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:

More examples

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");
Clone this wiki locally