title: How to Hex Encode a SHA-256 Hash
body: <p>How to Hex Encode a SHA-256 hash properly in C#?</p>
  
  <pre><code>private static string ToHex(byte[] bytes, bool upperCase)
  {
      StringBuilder result = new StringBuilder(bytes.Length * 2);
  
      for (int i = 0; i &lt; bytes.Length; i++)
          result.Append(bytes[i].ToString(upperCase ? "X2" : "x2"));
  
      return result.ToString();
  }
  
  private string hashRequestBody(string reqBody)
  {
      string hashString;
      using (var sha256 = SHA256Managed.Create())
      {
          var hash = sha256.ComputeHash(Encoding.Default.GetBytes(reqBody));
          hashString = ToHex(hash, false);
      }
  
      MessageBox.Show(hashString);
      return hashString;
  }
  </code></pre>
  
  <p>I did this, but the result is different with bank's sandbox I worked with.</p>
  
  <p>TEST DATA:</p>
  
  <p><code>{"CorporateID":"BCAAPI2016","SourceAccountNumber":"0201245680","TransactionID":"00000001","TransactionDate":"2017-09-13","ReferenceID":"refID","CurrencyCode":"IDR","Amount":"10000","BeneficiaryAccountNumber":"0201245681","Remark1":"Transfer Test","Remark2":"Online Transfer"}</code></p>
  
  <p>Bank's sandbox result: <code>e9d06986c1ed6b063bf59aa873030013725c518631deef2b2147e614017c2141</code></p>
  
  <p>Mine: <code>1c83acc42cf905ca8afba27ef0640c70ad2856a366b57c17cf16f2894327676e</code></p>