title: How to use Node crypto in NestJS to digest binary
body: <p>I am trying to port a pre-existing NodeJS project to NestJS.</p>
  <p>Rather than using require I am importing the library like so:</p>
  <pre><code>import * as crypto from 'crypto';
  </code></pre>
  <p>Most of the code works. However I am having issues with the following line:</p>
  <pre><code>const hash_digest   = hash.update(nonce + message).digest('binary');
  </code></pre>
  <p>The issue is &quot;binary&quot; does not appear to be a valid type. And indeed when I click through into the source located at node_modules/@types/node/crypto.d.ts, I see <code>BinaryToTextEncoding = 'base64' | 'hex';</code> are the only valid types for the digest method.</p>
  <p>However, when I <a href="https://node.readthedocs.io/en/latest/api/crypto/" rel="nofollow noreferrer">read the documentation</a> it states:</p>
  <pre><code>hash.digest([encoding])
  Calculates the digest of all of the passed data to be hashed. The encoding can be 'hex', 'binary' or 'base64'.
  </code></pre>
  <p>So is this a difference between the &quot;node&quot; and &quot;nestJS&quot; versions of this library or what am I missing?</p>
  <p>And if this is not a valid approach, how else to solve this problem? As it stands now, my nonce gets rejected as invalid if I try any of the following:</p>
  <pre><code>const hash_digest   = hash.update(nonce + message, 'binary').digest();
  </code></pre>
  <pre><code>const hash_digest   = hash.update(nonce + message).digest();
  </code></pre>
  <pre><code>const hash_digest   = hash.update(nonce + message, 'binary');
  </code></pre>
  <pre><code>hash_digest   = hash.update(nonce + message).digest(&lt;BinaryToTextEncoding&gt;'binary');
  </code></pre>