NodeJS HTML5视频元素播放来自存储器解密数据

d7v8vwbk  于 2022-12-12  发布在  Node.js
关注(0)|答案(1)|浏览(114)

我试图建立一个桌面应用程序与nodejs和电子播放加密(加密内置模块),嵌入式mp4视频文件。
下面是我的代码,它将解密的数据写入文件并通过它播放数据。有人能帮助我,使我的视频播放器通过内存播放数据,而不将数据写入文件吗?

var key ="12345678asdfghjk"
var keyBuf = new Buffer(key);
var inputStream = fs.createReadStream(file+"c");
var outputStream = fs.createWriteStream(file+"d");
var cipher = crypto.createDecipher("aes-128-cbc", keyBuf);

inputStream.on('data', function(data) {
  var buf = new Buffer(cipher.update(data), 'binary');
  outputStream.write(buf);
 });

inputStream.on('end', function() {
  try {
    var buf = new Buffer(cipher.final('binary'), 'binary');
    outputStream.write(buf);
    outputStream.end();
      
    outputStream.on('close', function() {       
    const introVideo=document.getElementById("introVideo");
    introVideo.src = "data:video/mp4;base64,"+fs.readFileSync(file+"d", "base64")
    introVideo.play()
        
    });
    } catch(e) {
     console.log(e)
    }
  });
fae0ux8s

fae0ux8s1#

decrypt(file) {
  return new Promise((resolve, reject) => { 
    const fs = require('fs'); 
    const crypto = require('crypto'); 
    const Buffer = require('buffer').Buffer; 
    const pass = new Buffer('"+key+"'); 
    const inputStream = fs.createReadStream(file); 
    const cipher = crypto.createDecipher('aes-128-cbc', pass); 

    var base64encodedData = ''; 

    inputStream.on('data', function(data) { 
      base64encodedData += new Buffer(
        cipher.update(data, 'binary', 'base64'),         
        'binary'
      ); 
    }); 

    inputStream.on('end', function() {
      base64encodedData += new Buffer(cipher.final('base64'), 'binary');
      return resolve(base64encodedData); 
    }); 
  }); 
}

我很抱歉延迟答复!@埃里克卡迈克尔如果你需要任何进一步的信息让我知道!

相关问题