fail to correctly encode and decode using java.util.Base64
<p>Let "awids" be 12 characters length ids in base 64 (<code>A-Z a-z 0-9 "-" "@"</code>). This is the input.</p>

<p>My final goal is to create a bijective mapping between these awids and <code>UUID</code>s, using some paddings, having as initial input the awids.</p>

<p>While trying to use <code>java.util.Base64</code> <strong>I do not get the initial value after a decoding and an encoding again. What is the stupid error I do?</strong> :)</p>

<p>With the reproducible example I present below the output is wrong because the input string is not gotten back after a <code>decode()</code>-<code>encode()</code> and the bijection is not preserved (<code>Q39s/L</code> and <code>Q39s/A</code> map both to the same value).</p>

<pre>
    ------------------------------------------> <strong>Q39s/L</strong> (6 [51 33 39 73 2f 4c]) 
    4 [43 7f 6c fc] -> 6 [51 33 39 73 2f 41] -> <strong>Q39s/A</strong> (6 [51 33 39 73 2f 41]) 
    4 [43 7f 6c fc] -> 6 [51 33 39 73 2f 41] -> <strong>Q39s/A</strong> (6 [51 33 39 73 2f 41])
</pre>

<p>Here a is a reproducible example:</p>

<pre>
<code>

    import java.nio.charset.StandardCharsets;
    import java.util.Base64;
    import java.util.StringJoiner;

    public class StackOverflowQuestion {

      public static void main(String[] args) {

        String halfAwid = "Q39s/L";

        byte[] sigBits = Base64.getDecoder().decode(halfAwid.getBytes(StandardCharsets.UTF_8));

        byte[] actualSigBits = Base64.getEncoder().withoutPadding().encode(sigBits);

        String actualHalfAwid = new String(actualSigBits, StandardCharsets.UTF_8);

        byte[] sigBits2 = Base64.getDecoder().decode(halfAwid.getBytes(StandardCharsets.UTF_8));
        byte[] actualSigBits2 = Base64.getEncoder().withoutPadding().encode(sigBits2);
        String actualHalfAwid2 = new String(actualSigBits2, StandardCharsets.UTF_8);

        System.out.println("----------------------------------------------> "
            + halfAwid + " (" + toHexString(halfAwid) + ") "
            + "\n"
            + "    "
            + toHexString(sigBits) + " -> "
            + toHexString(actualSigBits) + " -> "
            + actualHalfAwid + " (" + toHexString(actualHalfAwid) + ") "
            + "\n"
            + "    "
            + toHexString(sigBits2) + " -> "
            + toHexString(actualSigBits2) + " -> "
            + actualHalfAwid2 + " (" + toHexString(actualHalfAwid2) + ")"
            + "");
      }

      private static String toHexString(byte[] bytes) {
        StringJoiner joiner = new StringJoiner(" ", "" + bytes.length + " [", "]");
        for (byte b : bytes) {
          joiner.add(String.format("%02x", b));
        }
        return joiner.toString();
      }

      private static String toHexString(String text) {
        return toHexString(text.getBytes());
      }
    }

</code></pre>

<p>Do not hesitate to point any other errors I do in the code, even if they are not related directly to the question. Thank you.</p>