Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decode the name or namespace from a UUID

Tags:

uuid

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?

like image 900
Sathesh Avatar asked Oct 18 '25 19:10

Sathesh


1 Answers

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
like image 188
michaeldel Avatar answered Oct 22 '25 03:10

michaeldel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!