Skip to content
This repository
Browse code

docs: document crypto.randomBytes()

  • Loading branch information...
commit abfcd1fb00a386c846b77b026e30f0f140a3c2a6 1 parent 413d38c
Ben Noordhuis bnoordhuis authored

Showing 1 changed file with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. +18 0 doc/api/crypto.markdown
18 doc/api/crypto.markdown
Source Rendered
@@ -238,3 +238,21 @@ Sets the Diffie-Hellman private key. Key encoding can be `'binary'`, `'hex'`, or
238 238 Asynchronous PBKDF2 applies pseudorandom function HMAC-SHA1 to derive
239 239 a key of given length from the given password, salt and iterations.
240 240 The callback gets two arguments `(err, derivedKey)`.
  241 +
  242 +### randomBytes(size, [callback])
  243 +
  244 +Generates cryptographically strong pseudo-random data. Usage:
  245 +
  246 + // async
  247 + crypto.randomBytes(256, function(ex, buf) {
  248 + if (ex) throw ex;
  249 + console.log('Have %d bytes of random data: %s', buf.length, buf);
  250 + });
  251 +
  252 + // sync
  253 + try {
  254 + var buf = crypto.randomBytes(256);
  255 + console.log('Have %d bytes of random data: %s', buf.length, buf);
  256 + } catch (ex) {
  257 + // handle error
  258 + }

0 comments on commit abfcd1f

Please sign in to comment.
Something went wrong with that request. Please try again.