title: Javascript: AES encryption is slow
body: <p>I use <a href="https://www.npmjs.com/package/node-forge" rel="nofollow noreferrer">forge</a> as encryption library for both the gulp script (that performs encryption) and the front-end one (where in-browser decryption happens).</p>
  
  <p>The computer is a i5-6200U w/ 16GB ram and takes about 10 seconds for either symmetric enc. or decryption of a 15MB json file.</p>
  
  <p>My real issue is the decryption time being too long for users (multiple files to load and decrypt take 30s+ on this system).</p>
  
  <p>I'm certainly missing some key element (buffer or... whatever my lack of experience in the domain might miss). Is there something obviously wrong in the following code? Thanks for your attention.</p>
  
  <ol>
  <li><p>Obtaining the data</p>
  
  <pre><code>function logic(url){
  return new Promise( (resolve, reject) =&gt; {
  
      var xhr = new XMLHttpRequest();
      xhr.onload = function (event) {
          resolve(xhr.response);
      };
  
      xhr.onreject = function (err) {
          reject(err);
      }
  
      xhr.open('GET', url);
      xhr.send();
  });
  }
  </code></pre></li>
  <li><p>Decrypting the data</p>
  
  <pre><code>load('data/dicom.json').then( bytes =&gt; {
  
      const tIn = new Date().getTime();
  
      const forge = getForge();
      const pwd = "aStringPassword";
      const iv = getInitVector();
      const salt = getSalt();
  
      const key = forge.pkcs5.pbkdf2(pwd, salt, 100, 16);
  
      var decipher = forge.cipher.createDecipher('AES-CBC', key);
      decipher.start({iv: iv});
      decipher.update(forge.util.createBuffer(bytez));
      decipher.finish();
      const clear = decipher.output.getBytes();
  
      const tOut = new Date().getTime();
      console.log(`decrypted in ${(tOut - tIn) / 1000 }s`); // 10s for 15MB json file
  
      return clear ;
  });
  </code></pre></li>
  </ol>