title: PHP SHA-256 check sum in base64 to match that of Java
body: <p>I have java program which calculates SHA-256 checksum as follows. For example, if I provide the input <strong>abcd123ABCD00-4000</strong> it outputs <strong>0QtyIu4B+lU+TLqM/zfJz5ULVpyXgfLRs5mKXCQvbHM=</strong> . It also matches the <a href="http://hash.online-convert.com/sha256-generator" rel="nofollow">online check sum calculator</a>.</p>
  
  <p>However the PHP code I used won't match it.</p>
  
  <p>PHP code : </p>
  
  <pre><code>$s = 'abcd123ABCD00-4000';
  $signature = base64_encode(hash_hmac("sha256", $s, True)); 
  print  base64_encode($signature); 
  </code></pre>
  
  <p>Output : TWpRM1pEWXpaVFl4TURoallqTXdPRFV6WVRrNU5XVTRNRGxoWkRJMU1XWTVNREk1TnpBeU4ySXhaR0psTW1ZMk16Y3hPRE01WldFelkySXhOalJrWXc9PQ==</p>
  
  <p>Java Code : </p>
  
  <pre><code>private static String getSHA256Hash(String text) {
  
  
      String hash = null;
      MessageDigest md = null;
  
  
      try {
  
        md = MessageDigest.getInstance("SHA-256");
  
        md.update(text.getBytes("UTF-8"));
  
        byte[] shaDig = md.digest();
        // hash = Hex.encodeHexString(shaDig);
        hash = Base64.encodeBase64String(shaDig);
  
      } catch (NoSuchAlgorithmException ex) {
  
  
      } catch (UnsupportedEncodingException e) {
  
        e.printStackTrace();
      }
      return hash;
  
    }
  </code></pre>
  
  <p>Output : 0QtyIu4B+lU+TLqM/zfJz5ULVpyXgfLRs5mKXCQvbHM=</p>
  
  <p>Here what I want is to get the equivalent result in PHP (i.e to change PHP code to match result of the Java program[ I won't able to change the Java code ]. Any help is appreciated</p>