Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent encoding using "android.util.Base64" and "org.apache.commons.codec.binary.Base64;"
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload