Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert UUID back to String input - nameUUIDFromBytes

Tags:

java

I am using the function UUID.nameUUIDFromBytes(byte[]) to convert a string to UUID. Is it possible to convert back to the original string once I've got the UUID?

like image 406
andymal Avatar asked Sep 16 '15 22:09

andymal


People also ask

Can I convert UUID to string?

The toString() method of UUID class in Java is generally used to get the string representation of this UUID. Parameters: This method does not take any parameter. Return Value: This method returns a String value which is the string representation of this UUID.

Are UUIDs reversible?

This also means that one can (in theory) guarantee that some two inputs out there can wind up with the same UUID, and as a result, UUIDs are not generally reversible (however, in specific (limited) cases, perhaps they could be made reversible).

How do I return my UUID?

uuid1() is defined in UUID library and helps to generate the random id using MAC address and time component. bytes : Returns id in form of 16 byte string. int : Returns id in form of 128-bit integer. hex : Returns random id as 32 character hexadecimal string.

Is UUID a string or int?

The UUID as a 16-byte string (containing the six integer fields in big-endian byte order). The UUID as a 16-byte string (with time_low, time_mid, and time_hi_version in little-endian byte order). The UUID as a 32-character lowercase hexadecimal string. The UUID as a 128-bit integer.


2 Answers

Here's the Class description of UUID

UUID is an immutable representation of a 128-bit universally unique identifier (UUID).

There are multiple, variant layouts of UUIDs, but this class is based upon variant 2 of RFC 4122, the Leach-Salz variant. This class can be used to model alternate variants, but most of the methods will be unsupported in those cases; see each method for details.

So when you call nameUUIDFromBytes (byte[] name), it will return an UUID instance which is, again, a immutable representation of a 128bit universally unique identifier.

This means the byte is now hashed into a unique identifier and will not be reversible into the original byte.

What's the purpose of hashing bytes and why do you want to reverse it? If you specify that in your question, I will EDIT this post to give further help. But for now this is the answer.

like image 58
Saehun Sean Oh Avatar answered Sep 21 '22 05:09

Saehun Sean Oh


Name-based UUIDs use a hash function to map an input string to a fixed number of bits. Hash functions are lossy and are not generally reversible.

like image 36
chrylis -cautiouslyoptimistic- Avatar answered Sep 22 '22 05:09

chrylis -cautiouslyoptimistic-