Skip to content

Instantly share code, notes, and snippets.

@kbrsh
Last active November 30, 2016 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbrsh/867ca147063ae8082aeeb2721c180356 to your computer and use it in GitHub Desktop.
Save kbrsh/867ca147063ae8082aeeb2721c180356 to your computer and use it in GitHub Desktop.
Key - generate a random token
var crypto = require('crypto');
var apiKey = function(cb) {
crypto.randomBytes(7, function (err, bytes) {
key = new Buffer((new Date().valueOf()) + (bytes).toString('hex')).toString('base64');
cb(key);
});
}
// => MTQ4MDU0NjgzMjU1NTYxZTUwZDk3MWVmNTEz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment