Is it possible to decode the namespace or the name from a given UUID?
My idea is to generate the uuid with a particular namespace or name later and later retrieve it to check whether 2 UUIDs belong to the same namespace or name. Is this possible?
As stated in RFC4122, UUID3
and UUID5
namespaces and names are hashed (with either MD5 or SHA1), which means there is no other way to “decode” the namespace or name from a given UUID than bruteforce (that is the whole point of hash functions).
Compute the hash of the name space ID concatenated with the name.
RFC422 - 4.3 - Algorithm for Creating a Name-Based UUID
However you can directly compare the hashed namespaces and name to detect whether two UUIDs belong to the same namespace and have the same name, indeed. Here is an example in Python (using the standard uuid
module):
import uuid
name = 'stackoverflow.com'
a = uuid.uuid5(namespace=uuid.NAMESPACE_DNS, name=name)
b = uuid.uuid5(namespace=uuid.NAMESPACE_DNS, name=name)
assert a == b
print(a)
print(b)
cd84c40a-6019-50c7-87f7-178668ab9c8b
cd84c40a-6019-50c7-87f7-178668ab9c8b