Skip to content

Fix _crypto.randomBytes error - #1007

Closed
mahdipakravan-dev wants to merge 1 commit into
digitalbazaar:mainfrom
mahdipakravan-dev:main
Closed

mahdipakravan-dev wants to merge 1 commit into
digitalbazaar:mainfrom
mahdipakravan-dev:main

Conversation

@mahdipakravan-dev

Copy link
Copy Markdown

i fixed up this problem using nanoid to create randomBytes

@davidlehn

Copy link
Copy Markdown
Member

Thanks for the PR. We can't take this change: forge's PRNG needs raw bytes
from a cryptographically secure source, and crypto.randomBytes() is that
source in Node.js. nanoid returns a string from a 64-character alphabet
(6 bits per character instead of 8), it would add a runtime dependency, and
nanoid 4 is ESM-only, so require('nanoid') fails in forge's CommonJS
code. If you still see an error from _crypto.randomBytes, please open an
issue with the error message, the environment (Node.js version, bundler,
browser) and a small example. Closing this one.

@davidlehn davidlehn closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants