This commit is contained in:
n1474335 2022-11-25 11:13:05 +00:00
commit a4e20c7059
1 changed files with 6 additions and 2 deletions

View File

@ -52,8 +52,12 @@ class PseudoRandomNumberGenerator extends Operation {
let bytes;
if (isWorkerEnvironment() && self.crypto) {
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
bytes = Utils.arrayBufferToStr(bytes.buffer);
bytes = new ArrayBuffer(numBytes);
const CHUNK_SIZE = 65536;
for (let i = 0; i < numBytes; i += CHUNK_SIZE) {
self.crypto.getRandomValues(new Uint8Array(bytes, i, Math.min(numBytes - i, CHUNK_SIZE)));
}
bytes = Utils.arrayBufferToStr(bytes);
} else {
bytes = forge.random.getBytesSync(numBytes);
}