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