Skip to content

1.5. UUIDv5

Fabio Lima edited this page Sep 25, 2022 · 4 revisions

Name-based UUID with SHA-1 hashing

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