I made this picture that explains what I'm trying to achieve.
Brief summary: I want users to be able to upload an encrypted video that only those which have the password will be able to see as a stream. The point of all this is for the server to not be able to decipher it.
What I managed to do at the moment is only the first part, encrypting the chunks and sending them :
fileInput.addEventListener("change", async () => {
const file = fileInput.files[0]
const stream = file.stream()
const reader = stream.getReader()
while(true) {
const {value, done} = await reader.read()
if(done) break
handleChunk(value)
}
const out = {
size: file.size,
type: file.type,
encryptedStream: encryptedStream
}
})
function handleChunk(chunk) { // chunk: Uint8Array
const parsedChunk = CryptoJS.enc.Utf8.parse(chunk)
encryptedStream.push(CryptoJS.AES.encrypt(parsedChunk, "encryptionKey").toString())
}
I guess you can also do this with File.slice() but I did not test it.
At this point I feel like I've looked into every API related to files/streams both in Node and in vanilla js but I can't find a way to make this work, all I've managed is to make a Readable out of the encryptedStream array in the backend.
const Readable = require("stream").Readable
let readable = new Readable()
encryptedStream.forEach(aesChunk => readable.push(aesChunk))
readable.push(null)
I have doubts on how to stream it back to another frontend and literally no idea on how to play the video after deciphering it. From what I've looked online, it looks like it's not possible to stream a crypted file, only to download it.
Is this possible to do ?