Can NodeJS Crypto Handle Video Files?

Viewed 199

I cannot get why the video files cannot be encrypted and then decrypted. When then I try to open the resulting file, it says "This file isn't playable. That might be because the file type is unsupported, the file extension is incorrect, or the file is corrupt.". The same code works perfectly well with audio files. Here is the snippet:

// Nodejs encryption of buffers
const crypto = require('crypto'),
    algorithm = 'aes-256-cbc',
    password = 'd6F3Efeq';

const fs = require('fs');

let r = fs.createReadStream('video.mp4');
let encrypt = crypto.createCipher(algorithm, password);
let decrypt = crypto.createDecipher(algorithm, password);
let w = fs.createWriteStream('video.out4.mp4');

r.pipe(encrypt).pipe(decrypt).pipe(w);
0 Answers
Related