Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayBuffer and createBuffer #89

Closed
mixxr opened this issue Nov 30, 2013 · 1 comment
Closed

ArrayBuffer and createBuffer #89

mixxr opened this issue Nov 30, 2013 · 1 comment

Comments

@mixxr
Copy link

mixxr commented Nov 30, 2013

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:

            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

@dlongley
Copy link
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants