brix / crypto-js

JavaScript library of crypto standards.
Other
15.87k stars 2.39k forks source link

For super large ArrayBuffer, encryption will report RangeError: Invalid array length #497

Open Jeggery opened 3 months ago

Jeggery commented 3 months ago

I have a file that is binary and I want to encrypt it. However, when converting from an ArrayBuffer to a wordArray, an error occurs. export function arrayBufferToWordArray(ab: ArrayBuffer) { var i8a = new Uint8Array(ab); var a: number[] = []; for (var i = 0; i < i8a.length; i += 4) { var word = 0; for (var j = 0; j < 4 && i + j < i8a.length; j++) { word |= i8a[i + j] << (24 - j * 8); } a.push(word); // a.push((i8a[i] << 24) | (i8a[i + 1] << 16) | (i8a[i + 2] << 8) | i8a[i + 3]); } } Array a will display Invalid array length