Hi all,
I had the same problem with CryptoJS so I am assuming that it is actually not directly related to the JS libraries, but I am using an ArrayBuffer to read in a file in the browser and then encrypt it.
I have some sample code (referencing CryptoJS) here:
https://gist.github.com/thoraxe/4d4fa78bdc0b4605eed9The binary file in question is attached - a 1pixel GIF file.
Here's my post on the CryptoJS list:
https://groups.google.com/forum/#!topic/crypto-js/_aey7e7rQPMLong story short, when encrypting and then decrypting the file, I am ending up with extra bytes. Original file:
$ xxd 1pix.gif
0000000: 4749 4638 3961 0100 0100 8000 00ff ffff GIF89a..........
0000010: ffff ff21 fe11 4372 6561 7465 6420 7769 ...!..Created wi
0000020: 7468 2047 494d 5000 2c00 0000 0001 0001 th GIMP.,.......
0000030: 0000 0202 4401 003b ....D..;And here's the hex for the resulting file produced with SJCL:
$ xxd 1pixtest.gif
0000000: 4749 4638 3961 0100 0100 c280 0000 c3bf GIF89a..........
0000010: c3bf c3bf c3bf c3bf c3bf 21c3 be11 4372 ..........!...Cr
0000020: 6561 7465 6420 7769 7468 2047 494d 5000 eated with GIMP.
0000030: 2c00 0000 0001 0001 0000 0202 4401 003b ,...........D..;This thread on SJCL list references BinaryString:
https://groups.google.com/forum/#!topic/sjcl-discuss/iVbb6X9S2a0But I would think that, if not slicing, using BinaryString on a large file might be quite painful.
Is ArrayBuffer really the problem, or is my understanding of how to use it the issue? Encrypting the ArrayBuffer directly definitely did not work, so I was essentially using this method:
http://stackoverflow.com/questions/20324339/sjcl-encryption-results-wrong-file-sizeThis effectively converts the ArrayBuffer contents to a Uint8 array.
I'm totally lost on how to make this work.