Skip to content

Conversation

jimhark
Copy link

@jimhark jimhark commented Jul 20, 2025

Summary

Previously, HexEncoder.stringify could throw a "RangeError: Invalid array length" exception when processing large files. To workaround this, on Node, HexEncoder.stringify now uses Buffer.toString('hex').

Fixes

Fixes #213

Details

  • There are now different versions of HexEncoder for Node and browser, active version is selected at startup
  • Using built-in Node Buffer function is much faster.

Testing

I manually tested node encrypt, node decrypt, and HTML wrapper decrypt.

jimhark and others added 2 commits July 20, 2025 12:07
This is part of a push to support larger files. The focus is the switch
to using Uint8Array to store binary data. But also includes:

- When running on Node, use Buffer.from() for hex string conversions.

- To avoid large buffer copy, signedMsg as been replaced by an object
    containing  iv, encrypted, and hmac.

- hmac calculation has changed so it avoids copying (possibly very
    large) encrypted data. See signDigest() in lib/codec.js.

- Minor cleanup

Handling hex encode/decode at the input/output boundaries and using
Uint8Array internally for representing binary data has these benefits:

- More memory efficient, allows processing of 2x larger files.

- Aligns with cryptographic best practices: hashing is now performed
  on raw binary data (Uint8Array) instead of hex strings.

- Behavior is (mostly) unchanged
  - scripts/index_template.html textContent is not implemented and
    needs to be redesigned.
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

Successfully merging this pull request may close these issues.

cryptoENgine.js/HexEncoder.stringify() throws RangeError: Invalid array length
1 participant