Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
docs: document crypto.randomBytes()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Sep 27, 2011
1 parent 413d38c commit abfcd1f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doc/api/crypto.markdown
Expand Up @@ -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
}

0 comments on commit abfcd1f

Please sign in to comment.