diff --git a/doc/api/crypto.md b/doc/api/crypto.md index e5b83eb4ff5dd0..470c8f6641839a 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -4139,7 +4139,9 @@ added: v17.4.0 * `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer} * Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`. -A convenient alias for [`crypto.webcrypto.getRandomValues()`][]. +A convenient alias for [`crypto.webcrypto.getRandomValues()`][]. This +implementation is not compliant with the Web Crypto spec, to write +web-compatible code use [`crypto.webcrypto.getRandomValues()`][] instead. ### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)` diff --git a/lib/crypto.js b/lib/crypto.js index ac601a7664697d..a839f5fe27b029 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -252,6 +252,10 @@ function getFipsForced() { return 1; } +function getRandomValues(array) { + return lazyWebCrypto().crypto.getRandomValues(array); +} + ObjectDefineProperty(constants, 'defaultCipherList', { value: getOptionValue('--tls-cipher-list') }); @@ -303,7 +307,7 @@ ObjectDefineProperties(module.exports, { getRandomValues: { configurable: false, enumerable: true, - get() { return lazyWebCrypto().crypto.getRandomValues; }, + get: () => getRandomValues, set: undefined, },