title: base64 to hex inconsistent results
body: <p>Yesterday, I wrote a unit test in java. The routine I was testing needed to convert a base64 in hex and back. </p>
  
  <p>In my test, I used the string <code>myEvent=</code> for the base64. In hex, it becomes <code>9B212F7A7B</code>, but when I convert the hex back to base64, I get <code>myEvens=</code>. </p>
  
  <p>Why is this happening? I tried different libs and tools and it always give me this result.</p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  
  import javax.xml.bind.DatatypeConverter;
  
  class Rextester
  {  
      public static void main(String args[])
      {
          String data1 = "myEvent=";
          String hex1 = convertBase64StringToBase16(data1); // 9B212F7A7B
          String data2 = convertBase16StringtoBase64(hex1); // myEvens=
          String hex2 = convertBase64StringToBase16(data2); // 9B212F7A7B 
          System.out.println("data1=" + data1);
          System.out.println("data2=" + data2);
          System.out.println("hex1=" + hex1);
          System.out.println("hex2=" + hex2);
      }
  
      private static String convertBase16StringtoBase64(String base16) {
          return Base64.getUrlEncoder().encodeToString(DatatypeConverter.parseHexBinary(base16));
      }
  
      public static String convertBase64StringToBase16(String base64) {
          return DatatypeConverter.printHexBinary(Base64.getUrlDecoder().decode(base64));
      }
  }
  </code></pre>
  
  <p>Live demo: <a href="http://rextester.com/JFDYO56442" rel="nofollow">http://rextester.com/JFDYO56442</a></p>