Class: Crypto

  • Added in: v15.0.0

Calling require('crypto').webcrypto returns an instance of the Crypto class. Crypto is a singleton that provides access to the remainder of the crypto API.

Example:

const privateKey = new Uint8Array(32);
const webcrypto = require('crypto').webcrypto;
webcrypto.getRandomValues(privateKey);

Result:

÷ÆVY{ñÕÓ»ÃVíA0²†xò¥x´ü^18

Answer from Lawrence Cherone on Stack Overflow
🌐
GitHub
github.com › vitejs › vite › issues › 19407
Vite 6.1.0: TypeError: crypto$2.getRandomValues is not a ...
February 12, 2025 - Vite 6.1.0: TypeError: crypto$2.getRandomValues is not a function in Node.js versions >=18#19407 · Copy link · Labels · pending triage · likhith-ts · opened · on Feb 12, 2025 · Issue body actions ·
Author   likhith-ts
🌐
Render
community.render.com › t › crypto-getrandomvalues-is-not-a-function › 10559
crypto.getRandomValues() is not a function - Render
March 25, 2023 - Hi, I have a NodeJS server that has a function like this: uuidv4: function() { return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / …
🌐
Drupal
drupal.org › project › experience_builder › issues › 3504623
TypeError: crypto$2.getRandomValues is not a function
May 14, 2025 - Overview Encountered this error while executing the frontend tooling as per the steps in CONTRIBUTING.md (dev version of this module): error during build: TypeError: crypto$2.getRandomValues is not a function at resolveConfig (file://web/modules/contrib/experience_builder/ui/node_modules/v...
🌐
Sanity
sanity.io › exchange › answers › sanity dev server fails with "crypto.getrandomvalu...
Sanity dev server fails with "crypto.getRandomValues is not a function"...
November 29, 2025 - The crypto$2.getRandomValues is not a function error is a symptom of Vite (which Sanity Studio uses under the hood) trying to use crypto APIs that aren't available or are implemented differently in older Node.js versions.
🌐
Medium
medium.com › @manthankaslemk › how-to-fix-crypto-getrandomvalues-error-in-react-native-with-hermes-engine-8637cdf58e65
How to Fix crypto.getRandomValues() Error in React Native with Hermes Engine | by Manthan Kasle | Medium
April 29, 2025 - Hermes, the optimized JS engine used by React Native CLI projects, does not provide a native implementation of crypto.getRandomValues(). As a result, when such libraries attempt to access crypto.getRandomValues(), they throw an error and cause your app to crash. Source of error: Hermes missing crypto.getRandomValues → Libraries like uuid rely on it → App breaks at runtime. ✅ The solution is to polyfill crypto.getRandomValues() manually using the package react-native-get-random-values.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Crypto › getRandomValues
Crypto: getRandomValues() method - Web APIs | MDN
To guarantee enough performance, ... across user agents, but is suitable for cryptographic purposes. getRandomValues() is the only member of the Crypto interface which can be used from an insecure context....
Find elsewhere
🌐
Microsoft Community
community.fabric.microsoft.com › t5 › Developer › TypeError-cryptoObj-getRandomValues-is-not-a-function-unrelated › m-p › 1963294
Solved: TypeError: cryptoObj.getRandomValues is not a func... - Microsoft Fabric Community
July 20, 2021 - TypeError: cryptoObj.getRandomValues is not a function 12 | 13 | import React, { useState, useEffect } from 'react'; > 14 | import { models, Embed, service } from 'powerbi-client'; | ^ 15 | import { PowerBIEmbed } from 'powerbi-client-react'; 16 | import { appServices } from 'common/services'; 17 | import { useAccount, useMsal } from '@azure/msal-react'; at Function.WindowPostMessageProxy.createRandomString (node_modules/powerbi-client/dist/webpack:/powerbi-client/node_modules/window-post-message-proxy/dist/windowPostMessageProxy.js:125:1) at new WindowPostMessageProxy (node_modules/powerbi-cl
🌐
GitHub
github.com › openpgpjs › openpgpjs › issues › 22
Firefox: window.crypto.getRandomValues is not a function · Issue #22 · openpgpjs/openpgpjs
December 16, 2011 - Browser: Firefox Error: window.crypto.getRandomValues is not a function Source File: src/ciphers/openpgp.crypto.js Line: 424
Author   AlexanderWillner
🌐
GitHub
github.com › vuejs › vitepress › issues › 3090
RC21 Regression: "TypeError: crypto.getRandomValues is not a function" when deploying on GitHub pages · Issue #3090 · vuejs/vitepress
October 14, 2023 - Describe the bug > vitepress build docs vitepress v1.0.0-rc.21 - building client + server bundles... [vitepress] crypto.getRandomValues is not a function file: /home/runner/work/naninovel.github.io/naninovel.github.io/docs/guide/integrat...
Author   elringus
🌐
GitHub
github.com › aws › aws-sdk-js-v3 › discussions › 3950
Error: crypto.getRandomValues() not supported on node.js · aws/aws-sdk-js-v3 · Discussion #3950
import './polyfills/crypto' // rest of application code ... import crypto from 'crypto' // should have webcrypto.getRandomValues defined if (typeof global.crypto !== 'object') { global.crypto = crypto } if (typeof global.crypto.getRandomValues !== 'function') { global.crypto.getRandomValues = getRandomValues } function getRandomValues(array) { return crypto.webcrypto.getRandomValues(array) }
Author   aws
🌐
GitHub
github.com › denoland › std › issues › 2114
node: executing crypto.randomBytes says crypto.getRandomValues ​​is not a function · Issue #2114 · denoland/std
Describe the bug When I run crypto.randomBytes, it says crypto.getRandomValues ​​is not a function Steps to Reproduce enter to deno repl > crypto.randomBytes(10) Uncaught TypeError: crypto.getRandomValues is not a function at generateRan...
🌐
GitHub
github.com › electron-vite › electron-vite-vue › issues › 537
when run the project :crypto$2.getRandomValues is not a function · Issue #537 · electron-vite/electron-vite-vue
September 15, 2025 - when run the project :crypto$2.getRandomValues is not a function#537 · Copy link · Labels · bugSomething isn't workingSomething isn't working · remember-study · opened · on Sep 15, 2025 · Issue body actions · Reactions are currently unavailable · No one assigned ·
Author   remember-study
🌐
GitHub
github.com › einfallstoll › express-ntlm › issues › 71
TypeError: crypto.getRandomValues is not a function · Issue #71 · einfallstoll/express-ntlm
June 14, 2020 - npm 6.13.1 node v12.16.2 config: { "domain": "myhost", "domaincontroller": "ldap://dddd.myhost.org" } If connection to domain is unreacheable and you try go to some path (app.get) TypeError: crypto.getRandomValues is not a function at Ob...
🌐
W3Schools
w3schools.com › jsref › met_crypto_getrandomvalues.asp
JavaScript crypto API getRandomValues() Method
crypto.getRandomValues() returns the same array that is passed, with the contents replaced with new random numbers. The contents of the original array is not saved. The array must be a typedArray of integers: Int8Array · Uint8Array · ...
🌐
Railway
station.railway.com › home › questions › exit code 1 and exit code 137, please, i am just curious, what is the issue? i don't understand
exit code 1 and exit code 137, please, i am just curious, what is the issue? i don't understand - Railway Help Station
January 26, 2025 - TypeError: crypto$2.getRandomValues is not a function at resolveConfig (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:54251:16) at async createBuilder (file:///app/node_modules/vite/dist/node/chunks/dep-B0fRCRkQ.js:51949:18) at async CAC.<anonymous> (file:///app/node_modul...