Skip to content

Instantly share code, notes, and snippets.

@anoopemacs
Last active April 8, 2018 02:48
Show Gist options
  • Select an option

  • Save anoopemacs/78b1df1b516d9ad787944de0e90a398c to your computer and use it in GitHub Desktop.

Select an option

Save anoopemacs/78b1df1b516d9ad787944de0e90a398c to your computer and use it in GitHub Desktop.
// The resulting string will be twice as long as the random bytes you generate;
// each byte encoded to hex is 2 characters. 20 bytes will be 40 characters of hex.
require('crypto').randomBytes(48, function(err, buffer) {
var token = buffer.toString('hex');
});
// synchronous version
var token = require('crypto').randomBytes(64).toString('hex');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment