我正在尝试使用CryptoJS库加密视频。目标是加密它并将其存储在Firebase存储中。稍后,当您想要进行可视化时,它会被解密并作为URL添加到HTML视频标记中。解密后我无法显示视频,对问题是什么的任何想法?我觉得问题在于将密码的输出视为字符串。我不知道应该以什么方式对待它,以便继续保持视频文件的属性。提前谢谢。
目前的代码是:
//Encrypt and upload function
function almacenarFicheroGrabacionVideo(file) {
let storageRef = firebase.storage().ref('videos/' + file.name);
let reader = new FileReader();
reader.onload = function () {
let read = reader.result;
let task = storageRef.putString(CryptoJS.AES.encrypt(read, getCookie('key')).toString());
task.on('state_changed', function progress(snapshot) {
}, function error(err) {
console.log(err);
}, function complete() {
console.log("fichero subido");
});
};
reader.readAsText(file);
}
//Decrypt and visualize video
$scope.verVideo = function() {
firebase.storage().ref('videos/').child('Blurred Bokeh Video 2.mp4').getDownloadURL().then(function (url) {
fetch(url)
.then(res => res.blob()) // Gets the response and returns it as a blob
.then(blob => {
let reader = new FileReader();
reader.onload = function () {
let fileDown = CryptoJS.AES.decrypt(reader.result, getCookie('clave')).toString(CryptoJS.enc.Utf8);
var videoNode = document.getElementsByTagName('video')[0];
let blob = new Blob([fileDown], {type: "video/mp4"});
let url = URL.createObjectURL(blob);
let element = document.createElement('a');
element.setAttribute('href', url);
element.setAttribute('download', 'Blurred Bokeh Video 2.mp4');
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
};
reader.readAsText(blob);
});
}).catch(function (error) {
// Handle any errors
console.log(error);
});
};