Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to reverse Python uuid5() to its value?

Tags:

python

uuid

can it be reversed? if I use

>>> RESOURCE_ID_NAMESPACE = uuid.UUID('0a7a15ff-aa13-4ac2-897c-9bdf30ce175b')
>>> value = 'test'
>>> uuid.uuid5(RESOURCE_ID_NAMESPACE, value)
UUID('7fd19145-920f-5b9c-be0a-2146b0c39949')

if I know the uuid5 value, can I get the value 'test'?

thanks a lot.

like image 928
Pzhang Avatar asked Nov 29 '16 03:11

Pzhang


People also ask

How do you use uuid in Python?

The uuid module provides immutable UUID objects (the UUID class) and the functions uuid1() , uuid3() , uuid4() , uuid5() for generating version 1, 3, 4, and 5 UUIDs as specified in RFC 4122. If all you want is a unique ID, you should probably call uuid1() or uuid4() .

How do I get the uuid in Python?

UUID 1 to Generate a unique ID using MAC Address The uuid. uuid1() function is used to generate a UUID from the host ID, sequence number, and the current time. It uses the MAC address of a host as a source of uniqueness.

What is uuid5?

uuid5(namespace, string) : This function uses SHA-1 hash value of namespaces mentioned with a string to generate a random id of that particular string.

Is uuid standard library Python?

UUID, Universal Unique Identifier, is a python library which helps in generating random objects of 128 bits as ids.


2 Answers

UUID version 5 is based on the SHA-1 hash of the input. The whole point of cryptographic hashing algorithms is that they're nearly impossible to reverse in the general case.

If you know the input was a dictionary word, sure, you could just generate a uuid5 value for every word in the dictionary, same goes for when you know it's a short string of letters, but in the general case, no, you can't reverse a UUID5 value any more than you can a cryptographic hash. And no, the weaknesses in SHA-1 are unlikely to be helpful here; they're useful largely in generating collisions, but not recovering the original value.

like image 126
ShadowRanger Avatar answered Oct 12 '22 14:10

ShadowRanger


No, you cannot. The uuid is created by hashing the namespace and value you pass into the constructor. But there are an infinite number of other possible strings (although they're probably hard to find) that hash to the same value. So there's no way to determine what the original string was that constructed the uuid.

like image 21
happydave Avatar answered Oct 12 '22 14:10

happydave