title: SHA 256 Different Result
body: <p>If I invoke the command from Mac</p>
  
  <pre><code>echo hello | shasum -a 256
  </code></pre>
  
  <p>or from ubuntu</p>
  
  <pre><code>echo hello | sha256sum
  </code></pre>
  
  <p>Then I get the following result</p>
  
  <pre><code>5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03  -
  </code></pre>
  
  <p>I notice there is dash at the end.</p>
  
  <p>But when I use Python <code>hashlib</code> or Java <code>java.security.MessageDigest</code>, they give me the same result as follows:</p>
  
  <pre><code>2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
  </code></pre>
  
  <p>So, could anyone point out where I got it wrong please? </p>
  
  <p>Thanks. </p>
  
  <hr>
  
  <p>Python:</p>
  
  <pre><code>&gt;&gt;&gt; import hashlib
  &gt;&gt;&gt; hashlib.sha256("hello").hexdigest()
  </code></pre>
  
  <p>Java:</p>
  
  <pre><code>MessageDigest md = MessageDigest.getInstance("SHA-256");
  String text = "hello";
  md.update(text.getBytes("UTF-8"));
  byte[] digest = md.digest();
  StringBuffer sb = new StringBuffer();
  for (int i = 0; i &lt; digest.length; i++) {
      sb.append(String.format("%02x", digest[i] &amp; 0xFF))
  }
  System.out.println(sb.toString());
  </code></pre>