title: SHA256 encryption in JAVA and PYTHON produce different results
body: <p>I would appreciate your help to understand why my SHA256 encryption function in JAVA and in PYTHON does not produce the result (difference in 1 digit, one more in python):</p>
  
  <p>hash to encrypt is: "thisisatest"<br>
  Java results is: <code>a7c96262c21db9a06fd49e307d694fd95f624569f9b35bb3ffacd88044f9787</code><br>
  Python result is: 
  <code>a7c96262c21db9a06fd49e307d694fd95f624569f9b35bb3ffacd880440f9787</code></p>
  
  <p>Python code:  </p>
  
  <pre><code>import hashlib
  
  def encrypt_string(hash_string):
      sha_signature = \
          hashlib.sha256(hash_string.encode()).hexdigest()
      return sha_signature
  
  
  hash_string = "thisisatest"
  print(encrypt_string(hash_string), end="")
  </code></pre>
  
  <p>Java code:  </p>
  
  <pre><code>import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  
  public class OpenAPIPasswordEncryptor1 {
  
  
      private static MessageDigest sha256;
  
      // generated password is stored encrypted (using also user name for hashing)
      public synchronized static String encrypt(String hash) {
          try {
  
              StringBuilder builder = new StringBuilder();
              builder.append(hash);
  
              // first time , encrypt user name , password and static key
              String encryptedCredentials = encryptionIterator(builder.toString());
             return encryptedCredentials;
          } 
  
          catch (Exception e) {
              e.printStackTrace();
          }
  
          return "";
      }
  
      private static String encryptionIterator(String content) {
          try {
              sha256 = MessageDigest.getInstance("SHA-256");
              // append the static key to each iteration
              byte[] passBytes = (content).getBytes();
              sha256.reset();
              byte[] digested = sha256.digest(passBytes);
              StringBuffer sb = new StringBuffer();
              for (int i = 0; i &lt; digested.length; i++) {
                  sb.append(Integer.toHexString(0xff &amp; digested[i]));
              }
  
              return sb.toString();
          } catch (NoSuchAlgorithmException ex) {
              ex.printStackTrace();
          }
  
          return "";
      }
  
      // generate password for developers
      public static void main(String[] args) {
          String hash = "thisisatest";
          String encrypt = encrypt(hash);
          System.out.println("Your Password Is '" + encrypt + "'");
      }
  }
  </code></pre>