title: NodeJS Crypto randomBytes to string hex doubling size
body: <p>I'm experiencing an odd issue using NodeJS crypto and the crypto.randomBtyes function. I've detected strange behaviorthat seems to have only recently appeared in my NodeJS / Typescript 3.2 application.</p>
  
  <blockquote>
    <p>The error makes sense in its own right: Invalid key length
        at Cipheriv.createCipherBase (internal/crypto/cipher.js:79:18)</p>
  </blockquote>
  
  <p>Upon inspecting the key length returned, it is doubling the requested number of bytes. I stated this as "odd" in that it was working previously (as of Thursday/Friday last week (3/7/2019 - 3/8/2019) but as of this morning the new behavior was detected. However, I haven't run any updates since so hopefully I'm missing something obvious. I could change my key size to be half of what I want, however, I wanted to see if I'm overlooking something simple before I implement a hack.</p>
  
  <p>Here is a fairly basic example of my crypto implementation.</p>
  
  <pre><code>import crypto = require('crypto');
  
  export class Encryption {
      static GenerateRandomBytesToHex(size: number): string {
          return crypto.randomBytes(size).toString('hex');
      }
  }
  </code></pre>
  
  <p>However when calling:</p>
  
  <pre><code>let cipherKey = Encryption.GenerateRandomBytesToHex(32);
  </code></pre>
  
  <p>It is returning a 64 character string rather than a 32 character string.</p>
  
  <blockquote>
    <p>Example:
    c8a8437677fcfab679f92c8470ffc34b932f5aaa3296c09f652d2becfe1db8b2 (64 characters in length)</p>
  </blockquote>
  
  <p>This is an implementation of the concepts outlined in this article:
  <a href="http://vancelucas.com/blog/stronger-encryption-and-decryption-in-node-js/" rel="nofollow noreferrer">http://vancelucas.com/blog/stronger-encryption-and-decryption-in-node-js/</a></p>
  
  <p>Any help would be greatly appreciated.</p>