title: Same hashing algorithm in Java and PHP gives different results
body: <p>I am integrating the same login functionality using same database on java and php platforms but having some problem in password algorithms.</p>
  
  <p>Here is my java code:-</p>
  
  <pre><code>public static String encryptPassword(String strToEncrypt,String saltToEncrypt)      
  {
      String encryptedString = "";
      String stringToEncrypt = "";
      byte[] encodedValue;
  
      stringToEncrypt = strToEncrypt + saltToEncrypt;
  
      encodedValue = Base64.encodeBase64(DigestUtils.sha256(stringToEncrypt
              .getBytes()));
      encryptedString = new String(encodedValue);
  
      return encryptedString;
  }
  </code></pre>
  
  <p>Here is my PHP code:-</p>
  
  <pre><code>  function  encryptPassword($strToEncrypt, $saltToEncrypt) 
    {
      $stringToEncrypt = $strToEncrypt.$saltToEncrypt;
  
      $encodedValue = base64_encode(hash('sha256', $stringToEncrypt));
  
      return $encodedValue;
   }
  </code></pre>
  
  <p>Ideally, both of these functions should generate the same encrypted string but these are giving different results.
  What is wrong with my code? Please advise.</p>