Open peter100u opened 3 years ago
export function encryptionFile(file, callback) { console.log('peter encryption file ', file, file.type); let fileReader = new FileReader(); fileReader.readAsArrayBuffer(file); fileReader.onload = () => { try { console.log('peter big size ' + fileReader.result); // 下面这行大文件会崩溃,如何做分片 // down line crash when file very big size let content = CryptoJS.lib.WordArray.create(fileReader.result); let decrypted = CryptoJS.AES.encrypt(content, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); const result = convertWordArrayToUint8Array(decrypted.ciphertext); let fileDecBlob = new Blob([result]); callback(fileDecBlob, result); } catch (e) { console.log("peter fail", e); } }; }
Yes you have to split the large file into chunks and I found this post super helpful
https://stackoverflow.com/a/62824083
When encrypting large files, running this line(CryptoJS.lib.WordArray.create(fileReader.result)) of code will crash