0


I wrote a function with the aim of decrypting a large file, but I keep getting this error when I call it: Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length.
The fun fact is that I never experienced this kind of error before, because the function seemed to work.
Basically what I'm doing is:

  • Opening up a file via RestAPI
  • Displaying its content on the frontend
  • Eventually editing its content
  • Saving the file when I finish editing it

The error appears after a couple of times I refresh the page to display the editing page (so when I read it and then I place all the stuff in the editor, where the user can modify it).
Code:

module.exports.read = (url) => {

  return new Promise(

    (resolve, reject) => {

      var key = config.aes
      var inp = fs.createReadStream("./files/" + url + ".ciocci"); //encrypted file 
      var decrypt = crypto.createDecipher('aes-256-cbc', key);
      var decrypted = fs.createWriteStream('./files/temp/' + url + '.deciocciato'); // decrypted file

      inp.pipe(decrypt).pipe(decrypted); // error line here

      decrypted.on('finish', () => {

        // code not reached            

        ... more stuff
  • Why did I get downvoted? –  Jan 23 '18 at 14:28
  • 1
    I'd be surprised if the person who downvoted actually replied to that question; --- as a response to your actual question: have you updated node recently? – Cody G Jan 23 '18 at 14:36
  • I.e., this pops up from a search of your error message https://stackoverflow.com/questions/21292142/decrypting-aes256-with-node-js-returns-wrong-final-block-length (very old node versions, but point being you may be experiencing an issue because the crypto library changes...) – Cody G Jan 23 '18 at 14:36
  • @CodyG. yes, I updated my Node.js version to the latest stable. The point is that after the update the error was showing up anyways, but this code worked for a while, then it started giving these kinds of error. –  Jan 23 '18 at 14:41
  • What was your previous version? Have you tried reverting back? (Well, it might have worked for a while as it destroyed all your data... (read OK, write bad) – Cody G Jan 23 '18 at 14:42
  • @CodyG. Node 8.8.1 –  Jan 23 '18 at 14:42
  • I guess the main question I have is : did everything work before you updated --- this is the only thing that has changed? – Cody G Jan 23 '18 at 14:44
  • I updated just a bunch of minutes ago, with this version and the 8.8.1 the error is exactly the same. –  Jan 23 '18 at 14:45
  • 1
    Ok thanks for ruling that out. – Cody G Jan 23 '18 at 14:45
  • Can you provide the stack trace? (where exactly is this error being thrown?) --- whoops just saw your comment line – Cody G Jan 23 '18 at 14:46
  • I think I don't have to "let Node finish doing something" because I'm piping everything. I really can't understand... –  Jan 23 '18 at 14:51
  • You should probably at least catch and log the read/write stream errors (`inp.on('error',callback)`), separate this function into a seperate CLI program to test it works under stress testing. That way you can rule out this particular process. – Cody G Jan 23 '18 at 15:04
  • I found out that the error is caused by "decrypt". More debug coming soon... –  Jan 23 '18 at 15:18

0 Answers0