Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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