title: decipher.final(): Unsupported state or unable to authenticate data
body: <p>I have the following code:</p>
  <pre class="lang-js prettyprint-override"><code>const crypto = require(&quot;crypto&quot;);
  
  const algorithm = &quot;aes-256-gcm&quot;; 
  const message = &quot;This is a secret message&quot;;
  const iv = crypto.randomBytes(12);
  const sKey = crypto.randomBytes(32);
  
  const cipher = crypto.createCipheriv(algorithm, sKey, iv);
  const decipher = crypto.createDecipheriv(algorithm, sKey, iv)
  
  let encryptedData = cipher.update(message, &quot;utf-8&quot;, &quot;hex&quot;);
  encryptedData += cipher.final(&quot;hex&quot;);
  
  let decData = decipher.update(encryptedData, &quot;hex&quot;, &quot;utf-8&quot;);
  decData += decipher.final(&quot;utf-8&quot;);
  
  console.log(&quot;Encrypted message: &quot; + encryptedData);
  console.log(&quot;Decrypted message: &quot;, decData)
  </code></pre>
  <p>When I run it, I receive the following exception:</p>
  <pre><code>node:internal/crypto/cipher:193
    const ret = this[kHandle].final();
                              ^
  
  Error: Unsupported state or unable to authenticate data
      at Decipheriv.final (node:internal/crypto/cipher:193:29)
      at Object.&lt;anonymous&gt; ([...]/crypto-test.js:15:21)
      at Module._compile (node:internal/modules/cjs/loader:1101:14)
      at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
      at Module.load (node:internal/modules/cjs/loader:981:32)
      at Function.Module._load (node:internal/modules/cjs/loader:822:12)
      at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
      at node:internal/main/run_main_module:17:47
  </code></pre>
  <p>Error is thrown when calling <code>decipher.final()</code>. How can I fix it?</p>