title: Different encoding using "android.util.Base64" and "org.apache.commons.codec.binary.Base64;"
body: <p>I am programming an authentication service in Android and this one includes a server part written in java.
  I do the same operations in both parts executing these two pieces of codes in Android and Server:</p>
  
  <p>ANDROID:</p>
  
  <pre><code>String genChallengeResponse(String challenge, String message) {
    String Hmac_ALG = "HmacSHA256";
    SecretKey key = new SecretKeySpec(challenge.getBytes(), Hmac_ALG);
    Mac m = Mac.getInstance(Hmac_ALG);
    m.init(key);
    m.update(password.getBytes());
    byte[] mac = m.doFinal();
    return new String(Base64.encode(mac, Base64.DEFAULT));
  }
  </code></pre>
  
  <p>SERVER:</p>
  
  <pre><code>String genChallengeResponse(String challenge, String message) {
    String Hmac_ALG = "HmacSHA256";
    SecretKey key = new SecretKeySpec(challenge.getBytes(), Hmac_ALG);
    Mac m = Mac.getInstance(Hmac_ALG);
    m.init(key);
    m.update(password.getBytes());
    byte[] mac = m.doFinal();
    return new String(Base64.encodeBase64(mac));
  }
  </code></pre>
  
  <p>Starting from the same challenge and message these are the results:</p>
  
  <pre>
  Android: n2EaLpQr0uKgkZKhCQzwuIFeeLjzZKerZcETVNcfla4=
  Server:  n2EaLpQr0uKgkZKhCQzwuD9eeLjzZKerZcETVNcfla4=
                                ^^
  </pre>
  
  <p>These are different just for TWO CHARACTERS.
  The problem is that this strange behaviour does not appear in every pair of String passed to the functions...</p>
  
  <p>I tried to use the UTF-8 in each system, but nothing changes...
  Do someone knows what is the problem? If this is a known problem...</p>
  
  <p>(is important to say that the problem is the same using Android 2.2 or also 4.0, then the problem is not the operating system, I think).</p>