Skip to content

Instantly share code, notes, and snippets.

@jeffwilcox
Created July 11, 2019 19:16
Show Gist options
  • Save jeffwilcox/e85481a47623be81e3184517cd51ab37 to your computer and use it in GitHub Desktop.
Save jeffwilcox/e85481a47623be81e3184517cd51ab37 to your computer and use it in GitHub Desktop.
Generating a token in Node.js
// simple JavaScript (Node.js CLI) generating of a key and token
const crypto = require('crypto');
const myKey = crypto.randomBytes(32).toString('base64');
console.log('This is your key. Store is very securely, i.e. KeyVault:');
console.log(myKey);
console.log();
const sha1 = crypto.createHash('sha1');
sha1.update(myKey);
const hashValue = sha1.digest('hex');
console.log('This is your token. Share this value to enable the key:');
console.log(hashValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment