title: is Base64.encodeBase64String() and new String(Base64.encodeBase64() TRUELY the same thing?
body: <p>I am coding an android app that using sha256 encryption. I try using</p>
  
  <pre><code>String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes())); 
  </code></pre>
  
  <p>But I I got a runtime error say <code>java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String</code>. I researched the issue and someone on stack suggested that android as an older version of the <code>org.apache.commons.codec.binary.Base64</code> implemented and there is a conflict between the version I am using and the the one that android implements so that why that method <code>Base64.encodeBase64String</code> is not found. here is the link to what i found as help <a href="https://stackoverflow.com/questions/7688644/java-lang-nosuchmethoderror-org-apache-commons-codec-binary-base64-encodebase64">java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String() in Java EE application</a>. The solution was to use </p>
  
  <pre><code>String hash = new String(Base64.encodeBase64(sha256_HMAC.doFinal(data.getBytes("UTF-8"))));
  </code></pre>
  
  <p>I did use that and it seems to work but because the has that I am getting does not match what the server I am working with is expecting. I am wondering if the two are truly equivalent.</p>
  
  <p>I used this link to implement the sha256 <a href="http://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#java" rel="nofollow noreferrer">http://www.jokecamp.com/blog/examples-of-creating-base64-hashes-using-hmac-sha256-in-different-languages/#java</a></p>
  
  <p>Here is my code I am using retrofit library for http method calls:</p>
  
  <pre><code>public static String ComputeHash(String[] dataArray, String privateKey) {
  
      String hash="";
  
      String data = "";
  
      for (String item : dataArray) {
          data += item;
      }
  
      try {
  
          Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
          SecretKeySpec secret_key = new SecretKeySpec(privateKey.getBytes(), "HmacSHA256");
          sha256_HMAC.init(secret_key);
  
          //hash = Base64.encodeBase64String(sha256_HMAC.doFinal(data.getBytes()));
          //hash = Base64.encodeToString(sha256_HMAC.doFinal(data.getBytes("UTF-8")), Base64.DEFAULT);
          hash = new String(Base64.encodeBase64(sha256_HMAC.doFinal(data.getBytes("UTF-8"))));
  
      } catch (Exception e) {
          Toast.makeText(MyApplication.getAppContext(), "Error", Toast.LENGTH_LONG).show();
      }
      return hash;
  }
  
  public &lt;S&gt; S createService(Class&lt;S&gt; serviceClass){
  
      stamp = String.valueOf(System.currentTimeMillis() / 1000);//get the number of seconds since the epoch
  
      String[] data = new String[]{"thisisatestpublickey", 1438915015+"", "GET"};
      expectedSignature = ComputeHash(data, "thisistestprivatekey");
  
      RequestInterceptor requestInterceptor = new RequestInterceptor() {
          @Override
          public void intercept(RequestFacade request) {
              request.addHeader("Authorization", "Basic YXZlbmdlcnM6bWlnaHR5bWluZHM=");
              request.addHeader(ApplicationConstants.PublicKeyHeaderName, "thisisatestpublickey");
              request.addHeader(ApplicationConstants.StampHeaderName, 1438915015+"");
              request.addHeader(ApplicationConstants.SignatureHeaderName, expectedSignature);
  
          }
      };
  
  
  }
  </code></pre>