kevlened / isomorphic-webcrypto

:game_die: webcrypto library for Node, React Native and IE11+
https://www.w3.org/TR/WebCryptoAPI/
MIT License
116 stars 42 forks source link

[getRandomValues] The value of "size" is out of range #15

Closed oleksandr-kuzmenko closed 5 years ago

oleksandr-kuzmenko commented 5 years ago

Hello! Thanks for the great library!

> var webCrypto = require('isomorphic-webcrypto');
undefined
> webCrypto.getRandomValues(new Uint8Array(100)).length
100
> webCrypto.getRandomValues(new Uint8Array(65536)).length
Thrown:
RangeError [ERR_OUT_OF_RANGE]: The value of "size" is out of range. It must be >= 0 && <= 2147483647. Received 4294967296
    at assertSize (internal/crypto/random.js:36:11)
    at Object.randomBytes (internal/crypto/random.js:48:10)
    at Crypto.getRandomValues (/home/alx/ws/testWebCrypto/node_modules/@trust/webcrypto/src/Crypto.js:54:31)
    at repl:1:11
    at Script.runInThisContext (vm.js:123:20)
    at REPLServer.defaultEval (repl.js:384:29)
    at bound (domain.js:415:14)
    at REPLServer.runBound [as eval] (domain.js:428:12)
    at REPLServer.onLine (repl.js:700:10)
    at REPLServer.emit (events.js:205:15)

Is this correct behavior, considering https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues (find 65536)?

kevlened commented 5 years ago

This appears to be fixed in v2. The node implementation is now backed by @peculiar/webcrypto instead of @trust/webcrypto (which is now archived).

Closing for now.