You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'm trying to read a file, encrypt it and send it.
The file is read via FileReader that returns a ArrayBuffer. When I try to pass it to forge.util.createBuffer(), it reads the content not like an octet stream but always returns "[object ArrayBuffer]" as a string.
I tried to convert it to Uint8Array but the result was the same (e.g. "[object Uint8Array]").
Here my code:
mcipher.start(iv);
var byteArray = new Uint8Array(evt.target.result)
var buf = forge.util.createBuffer(byteArray);
mcipher.update(buf);
mcipher.finish();
var encrypted = mcipher.output.data;
encrypted is always 32bytes in length (because it encrypts the string "[object Uint8Array]").
How can I convert the evt.target.result into a byte array?
many thx
mike
The text was updated successfully, but these errors were encountered:
@mixxr, forge was written before Typed Array support was available in every major browser. It uses a special string encoding internally to handle binary data. We do plan on switching forge's internals and APIs over to using Typed Arrays/ArrayBuffers (see: #60), we just haven't gotten around to it yet.
For now, I've added some quick support that will convert an ArrayBuffer or any ArrayBufferView (Typed array) to a forge buffer. The code snippet you have above should do what you were expecting with the latest release w/respect to converting a Uint8Array to a forge buffer.
Hello
'm trying to read a file, encrypt it and send it.
The file is read via FileReader that returns a ArrayBuffer. When I try to pass it to forge.util.createBuffer(), it reads the content not like an octet stream but always returns "[object ArrayBuffer]" as a string.
I tried to convert it to Uint8Array but the result was the same (e.g. "[object Uint8Array]").
Here my code:
encrypted is always 32bytes in length (because it encrypts the string "[object Uint8Array]").
How can I convert the evt.target.result into a byte array?
many thx
mike
The text was updated successfully, but these errors were encountered: