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