Are Base64 encoded UUIDs unique?

Termin4t0r :

This is an extension to this question

If the string which is being encoded is guaranteed to be unique, for example, a UUID , does this also mean that the base64 encoded string is also guaranteed to be unique?

If we consider the following Java example,

    UUID uuid = UUID.randomUUID();
    ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16])
            .putLong(uuid.getMostSignificantBits())
            .putLong(uuid.getLeastSignificantBits());

    String encodedUUID = Base64.getUrlEncoder()
                  .withoutPadding()
                  .encodeToString(byteBuffer.array());

Since uuid is unique, does this imply encodedUUID will also be unique? If so what are chances of collision in case of a large number of encoded UUIDs?

Alex Broadwin :

If the data is unique, it will be unique when base64 encoded.

Base64 encoding is a lossless representation of the encoded data. It's the same data, just represented using different symbols to encode it in a fairly high density, printable way.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=308408&siteId=1