From abfcd1fb00a386c846b77b026e30f0f140a3c2a6 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 22 Sep 2011 22:12:10 +0200 Subject: [PATCH] docs: document crypto.randomBytes() --- doc/api/crypto.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/doc/api/crypto.markdown b/doc/api/crypto.markdown index 68ca607fe8..d51b1fa0c0 100644 --- a/doc/api/crypto.markdown +++ b/doc/api/crypto.markdown @@ -238,3 +238,21 @@ Sets the Diffie-Hellman private key. Key encoding can be `'binary'`, `'hex'`, or Asynchronous PBKDF2 applies pseudorandom function HMAC-SHA1 to derive a key of given length from the given password, salt and iterations. The callback gets two arguments `(err, derivedKey)`. + +### randomBytes(size, [callback]) + +Generates cryptographically strong pseudo-random data. Usage: + + // async + crypto.randomBytes(256, function(ex, buf) { + if (ex) throw ex; + console.log('Have %d bytes of random data: %s', buf.length, buf); + }); + + // sync + try { + var buf = crypto.randomBytes(256); + console.log('Have %d bytes of random data: %s', buf.length, buf); + } catch (ex) { + // handle error + } \ No newline at end of file