Node js - Cifrar y descifrar archivo
Quiero cifrar el archivo en el lado del cliente y enviarlo al lado del servidor y descifrar
Pero cuando estoy usando el nodo js incorporado crypto Recibo un error
client.js
const crypto = require('crypto');
const cipher = crypto.createCipher('aes192', 'a password');
const encInput = fs.createReadStream("abc.txt");
const encOutput = fs.createWriteStream("abc.txt.enc");
encInput.pipe(cipher).pipe(encOutput).on('close', function() {
// DATA SENT TO SERVER SIDE
//USING PIPELINE TO SEND DATA TO SERVER
});
Esta parte se hace perfectamente, crea un archivo cifrado en el lado del cliente y lo envía al lado del servidor
Server.js
//receive Data
//AFTER RECEIVING FILE ON this side I run decrypt script
const crypto = require('crypto');
const decipher = crypto.createDecipher('aes192', 'a password');
const decInput = fs.createReadStream("abc.txt.enc");
const decOutput = fs.createWriteStream("abc.txt");
decInput.pipe(decipher).pipe(decOutput);
Y esto da un error
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
at Decipher._flush (internal/crypto/cipher.js:141:28)
at Decipher.prefinish (_stream_transform.js:141:10)
at Decipher.emit (events.js:182:13)
at prefinish (_stream_writable.js:630:14)
at finishMaybe (_stream_writable.js:638:5)
at afterWrite (_stream_writable.js:481:3)
at onwrite (_stream_writable.js:471:7)
at Decipher.afterTransform (_stream_transform.js:94:3)
at Decipher._transform (internal/crypto/cipher.js:136:3)
at Decipher.Transform._read (_stream_transform.js:190:10)
Emitted 'error' event at:
at Decipher.onerror (_stream_readable.js:687:12)
at Decipher.emit (events.js:182:13)
at done (_stream_transform.js:208:19)
at _flush (_stream_transform.js:142:7)
at Decipher._flush (internal/crypto/cipher.js:143:5)
at Decipher.prefinish (_stream_transform.js:141:10)
[... lines matching original stack trace ...]
at afterWrite (_stream_writable.js:481:3)
Sé que no hay ningún problema en el lado del cliente, está funcionando perfectamente enviando datos utilizando el socket de la tuber
** No hay problema en recibir datos también en el lado del servidor, solo el descifrado está creando un problema e idk por qué **
,Cualquier otra cosa que quieras saber sobre mi código, por favor dile a
Usando Nodo v10.6.0