Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

197
Views
CryptoJS errors when encrypting in electron app - Fatal JavaScript invalid size error 75209227

I am writing an electron app that can be used to backup data to IPFS. I seems to function alright if I do not encrypt the file, but the line where encryptedZipFile is declared is causing an error. I thought it could be the length of the encryption key, so I have hashed it to make it shorter, but it still isn't working. Any help would be much appreciated.

const encrypt = (dir) => {
  console.log(`Encrypting ${dir}`);
  const destinationDir = `./aes-${dir.substring(2, dir.length)}`;
  return new Promise((resolve, reject) => {
    let zipFile = '';
    const compressedDirReadStream = fs.createReadStream(dir, { encoding: 'base64' });
    
    compressedDirReadStream.on('data', (chunk) => zipFile += chunk);
    
    compressedDirReadStream.on('end', () => {
      console.log('end', zipFile.substring(0, 50));
      const encryptionKey = CryptoJS.MD5(apiKey).toString();
      const encryptedZipFile = CryptoJS.AES.encrypt(String(zipFile), encryptionKey).toString();
      const outputStream = fs.createWriteStream(destinationDir);
      outputStream.write(encryptedZipFile, 'base64');
      outputStream.on('error', (err) => reject(err));
      outputStream.on('close', () => resolve(destinationDir));
    });

    compressedDirReadStream.on('error', (err) => {
      console.error(err);
      reject(err);
    });
  });
};

Console error:

[1] #
[1] # Fatal error in , line 0
[1] # Fatal JavaScript invalid size error 75209227
[1] #
[1] #
[1] #
[1] #FailureMessage Object: 000000F6051FCAF0
[1]  1: 00007FF71C3AFAED node_api_get_module_file_name+18013
[1]  2: 00007FF71F65F22E GetMainTargetServices+1884958
[1]  3: 00007FF71A3EA7AE v8::Extension::set_auto_enable+2094
[1]  4: 00007FF71ADFCB46 cppgc::DefaultPlatform::MonotonicallyIncreasingTime+513126
[1]  5: 00007FF71E7B3CDB v8::Platform::SystemClockTimeMillis+209963
[1]  6: 00007FF71AE72C5B v8::internal::OSROptimizedCodeCache::GetBytecodeOffsetsFromSFI+162635
[1]  7: 00007FF69FECD67C
[1] [7148:0507/132020.334:ERROR:crashpad_client_win.cc(814)] not connected
[1] [electronmon] app exited with code 4294930435, waiting for change to restart it
7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs