-
Notifications
You must be signed in to change notification settings - Fork 796
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
efficient way to encrypt binary Uint8Array data #291
Comments
So, just to be clear on the problem, it sounds like you want to avoid using too much memory at once. Right now, you're essentially having to duplicate what you've got in a large Uint8Array by converting it into a forge buffer prior to encryption. Is that right? If so, you'll want to just convert your Uint8Array one small slice at a time, put that into a forge buffer, run the encryption process, and then get the result out and convert it back into a Uint8Array or do whatever else you want. You'll just have to write a bit of code to do that:
If you have questions about what to do with the output of As a side note, I think your Instead, it sounds like you've got a byte array full of arbitrary binary data (that should not be interpreted as a string) that you want to encrypt. Forge 0.6.x was written prior to TypedArray support in browsers, so its buffers use a string to internally represent arrays of bytes (this is the same format that node.js uses with its Anyway, all you need to do is get your data into a forge buffer so you can encrypt it. Don't try to convert a forge buffer to a string. If you're calling "toString" on a forge buffer somewhere in your code, that's probably the issue -- don't do that. |
@dlongley Thanks. I did misunderstand the character representation issue and based on your description I think that you are correct in that my Out of curiosity, is the plan for Thank you for your help! |
Sure!
Yes, though you may still need to wrap a Uint8Array in a forge buffer for certain operations. Doing so will not result in a data copy, however, it would just be an API adapter to keep things consistent. |
Howdy!
I'm looking for an efficient way to encrypt binary
Uint8Array
data using forge crypto. We have some rather large binary arrays (100-300kb) and I'm currently trying to convert these into strings efficiently so that we can encrypt them using forge.The problem we're running into is that converting to strings causes URI errors in certain scenarios. In general my impression is that this happens when two high byte values end up adjacent in the Uint8Array, producing a high UTF16 code such as
0xFFFF
which is a non-character value. Here is an example test case which fails:My question is whether there is a better way to do this conversion, either by:
Tagging @dlongley as he commented on Uint8Array support in a previous issue here:
#89
Thank you!
Ryan
The text was updated successfully, but these errors were encountered: