i am trying to encrypt files with JS during upload and then decrypt them during download - all clientside, with javascript (like Mega / tresorit).
So far, basic principle of my app is:
-upload: read file with HTML5 FileReader as a base 64 string, encrypt it with CryptoJS, then send to PhP
reader = new FileReader();
reader.onload = function(event) {
var encrypted = CryptoJS.AES.encrypt(event.target.result, "Secret Passphrase");
//send to PhP
}
reader.readAsDataURL(files[i]);
-download: get file as a string via XMLHTTP request, decrypt with CryptoJS and i am done.
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
{
if(rawFile.status === 200 || rawFile.status == 0)
{
var decryped= CryptoJS.AES.decrypt(rawFile.responseText, "Secret Passphrase");
//process....
}
}
}
The principle above is working fine with small files (few MBs), but i need to be able to work with bigger files too (at least 100MB).
Is there any nice way of doing it? Uploading may be probably solved by uploading encrypted chunks with HTML5 FileReader, but what about downloading? I was thinking about HTML5 FileSystem API, but it is no longer developed.
I am not asking anyone to code that for me, I just want to know what is the good/best way of doing it and what should I be googling / looking for.
Thanks you.