Search code examples
javahashuuid

Convert UUID back to String input - nameUUIDFromBytes


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

[1] https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html#nameUUIDFromBytes-byte:A-


Solution

  • 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.