I've been banging my head against the wall for the past day, I'm trying to decrypt a binary string and then write it using CryptoJS. I got it working but the thing that gives me a headache is it's performance. I'm using some dirty workarounds to do it at the moment, but I'm pretty sure there is a faster and more efficient way.
convertWordArrayToUint8Array(CryptoJS.AES.decrypt(base64ArrayBuffer(res), key))
//"key" is a 32 character string (passphrase)
//"res" is a binary string converted to an ArrayBuffer
Is my current attempt where I get the binary string as an ArrayBuffer with XMLHttpRequest, then convert it to a Base64 string and then decrypt it using CryptoJS. After decryption I convert the result to a Uint8 Array and write it into a file. It works, but it is pretty slow. Decrypting a 1 MB chunk in Chrome takes about 200ms and 100ms in Firefox.
Any help is appreciated!
Out of curiosity - why CryptoJS
I don't know much about it, but a lot of cryptographic functions you may need are readily available in the browser:
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/decrypt
If it's possible to use the native API, I am guessing it's going to be a fair bit faster than a JavaScript implementation.