title: Hash a hexadecimal number using SHA-256 in java
body: <p>I have written a code to hash a hexadecimal number using SHA-256 in Java. Please see my code.</p>
  <pre><code>import java.math.BigInteger;
  import java.security.MessageDigest;
  import java.security.NoSuchAlgorithmException;
  
  public class Test {
      
      public static void main (String[] args) throws NoSuchAlgorithmException {
          
          BigInteger x = new BigInteger(&quot;f35b&quot;, 16);
          
          MessageDigest md = MessageDigest.getInstance(&quot;SHA-256&quot;);
          md.update(x.byteValue());
          byte[] hashedXArray = md.digest();
          
          BigInteger hashedX = new BigInteger(hashedXArray);
          System.out.println(hashedX.toString(16));
          
      }
      
  }
  </code></pre>
  <p>Its result is...</p>
  <pre><code>245843abef9e72e7efac30138a994bf6301e7e1d7d7042a33d42e863d2638811
  </code></pre>
  <p>Then I hashed the same input using another third party application with SHA-256. Its answer was completely different from above output. It is...</p>
  <pre><code>cd05094b5c5a5b80386da4fcfdd20e6ef5d363d97834ac8705e9832e6bd97f39
  </code></pre>
  <p>I still do not understand why my code result is far different from the actual value of sha256 of hexadecimal &quot;f35b&quot; and how can I resolve my code?</p>