我正在尝试用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)
}
});
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);
});
});
}
我很抱歉延迟答复!@Eric Carmichael如果你需要任何进一步的信息请告诉我!