digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.06k stars 779 forks source link

Page dies when encrypting large files #961

Open chiahsoon opened 2 years ago

chiahsoon commented 2 years ago

Hi! I'm trying to encrypt large file sizes (>= 1 GB) using AES-GCM, but when i try to upload a 1GB file, the page dies before finishing the encryption.

Pretty sure i'm missing some relevant javascript concepts here but any direction/help will be very much appreciated! My code currently looks something like this:

  // arrBuf represents file.arrayBuffer();
  const cipher = forge.cipher.createCipher('AES-GCM', key);
  cipher.start({
      iv: iv,
      additionalData: '',
      tagLength: 128,
  });
  const chunkSize = 1024 * 64;
  for (let idx = 0; idx < arrBuf.byteLength; idx += chunkSize) {
      const slice = arrBuf.slice(idx, idx + chunkSize);
      cipher.update(forge.util.createBuffer(slice)); 
  }
  cipher.finish();
PierreJeanjacquot commented 1 year ago

Hi @chiahsoon, I see 2 issues: