javascript - Encrypting files with SJCL client-side -


I have trouble encrypting files with SJCL and Javascript.

I have been able to encrypt the text files using the FileReader API and readAsBinaryString. When it comes to PDF / PNG / Encryption, the problem probably arranges because of the encoding.

I found that I can use readAsArrayBuffer which considers this work to be completely appropriate, so I basically read the file and create a new type array New Uint8Array () But I do not know what I really need to do to encrypt such data.

Here's my code:

  / ** Convert bits from an array of bytes to bits. * / Function to BetterErrorcode (bytes) {var out = [], i, tmp = 0; For (i = 0; i > 24); TMP & lt; & Lt; = 8; } Exit; } Var Reader = New FileReader (); Reader.readAsArrayBuffer (fileData); // The claimant comes from the reader function. Open = function () {var bytes = new UIT 8 array (reader.Selt); Var bits = tobitArrayCodec (bytes); Var crypt = sjcl.encrypt ("aaaaa", bits); Var decrypt = sjcl.decrypt ("aaaaa", crypt); Var byteNumbers = fromBitArrayCodec (decrypt); Var Bitere = new UIT 8 array (bi-level); SaveData (Bytere, 'PNG.');  

I'm having an error

  Uncaught URIError: UI malformed sjcl.js: 12sjcl.codec.utf8String.fromBits sjcl.js: 12sjcl.json decrypt Sjcl.js: 44reader.onload  

I should be aware of encrypting uint8array or how to encrypt other options (PDF / PNG / ..) Files

The plain text is expected to be utf8 encoded in sjcl. Encrypting manually created bit arrays, because encryption is done on bitarre and does not have to decode it. But at the end of the decryption, there is an encoding step that changes the plain text bitrate into a UTF 8 string. It does not work, because it has unexpected characters because the source was probably binary.

The solution will encode it before encrypting it as base 64 and will return it after decrypting it.

  var bytes = new Uint8Array (reader.result); Var bits = tobitArrayCodec (bytes); Var base64bits = sjcl.codec.base64.fromBits (beats); // added var crypt = sjcl.encrypt ("aaaaa", base64bits); Var base64decrypt = sjcl.decrypt ("aaaaa", crypt); Var decrypt = sjcl.codec.base64.toBits (base64decrypt); // added white bytes = citraterecode (decrypt); Var Bitere = new UIT 8 array (bi-level);  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -