title: How to compute an SHA256 hash and Base64 String encoding in JavaScript/Node
body: <p>I am trying to recreate the following C# code in JavaScript.</p>
  
  <pre><code>SHA256 myHash = new SHA256Managed();
  Byte[] inputBytes = Encoding.ASCII.GetBytes("test");
  myHash.ComputeHash(inputBytes);
  return Convert.ToBase64String(myHash.Hash);
  </code></pre>
  
  <p>this code returns <code>"n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg="</code></p>
  
  <p>This is what I have so far for my JavaScript code</p>
  
  <pre><code>var sha256 = require('js-sha256').sha256;
  var Base64 = require('js-base64').Base64;
  
  var sha256sig = sha256("test");
  
  return Base64.encode(sha256sig);
  </code></pre>
  
  <p>the JS code returns <code>"OWY4NmQwODE4ODRjN2Q2NTlhMmZlYWEwYzU1YWQwMTVhM2JmNGYxYjJiMGI4MjJjZDE1ZDZjMTViMGYwMGEwOA=="</code></p>
  
  <p>These are the 2 JS libraries that I have used</p>
  
  <p><a href="https://www.npmjs.com/package/js-sha256" rel="nofollow noreferrer">js-sha256</a></p>
  
  <p><a href="https://www.npmjs.com/package/js-base64" rel="nofollow noreferrer">js-base64</a></p>
  
  <p>Does anybody know how to make it work ? Am I using the wrong libs ?</p>