title: Basic Auth Authorization header and base 64 encoding
body: <p>I have a vendor that I wish to exchange data with. They want me to take the username and password that they gave me and use it on an Authorization header for a get request.</p>
  <p>And now my dirty little secret. I've never created an Authorization header before.</p>
  <p>So I do a bunch of research and figure out the following code.</p>
  <pre><code>public static final String          AUTH_SEPARATOR = &quot;:&quot;;
  private static final String         AUTH_TYPE = &quot;Basic &quot;;
  public static final String          HEADER_AUTHORIZATION = &quot;Authorization&quot;;
  
  public static void addAuthHeader(Map&lt;String, String&gt; headers, String user, String password) {
      String secretKey = user
              + AUTH_SEPARATOR
              + password;
      byte[] tokenBytes = secretKey.getBytes();
      String token64 = Base64.getEncoder().encodeToString(tokenBytes);
      String auth = AUTH_TYPE + token64;
      headers.put(HEADER_AUTHORIZATION, auth);
  }
  </code></pre>
  <p>I run it and I get no response back. Hmmm. So I go to open a support request with them and I want to create an example, so I open postman and use the APIs they gave me for postman. First, I run the one for the API I'm replicating and it works. Hmm.</p>
  <p>So then I modify that API and use my username and password instead of the one included in the example and it works fine. Crikey!</p>
  <p>So I bang around a bit and notice that the Base64 string in the auth created by postman is slightly different at the end than the one I created.</p>
  <p>So, back to the research and all the code I find looks a lot like mine, although I had to update it some because of version differences. The string is still different and now I'm asking for help. Surely someone has solved this problem.</p>
  <p>String from postman &quot;Basic THVKZ...FvTg==&quot;
  String from code above &quot;Basic THVKZ...FvTiA=&quot;</p>
  <p>How did I do something wrong and end up with only a three byte difference?</p>