Skip to content

Instantly share code, notes, and snippets.

@aryomuzakki
Forked from dehamzah/generate.js
Last active September 14, 2023 14:42
Show Gist options
  • Save aryomuzakki/c995a537068b91cdbd9a7c8856b54bd5 to your computer and use it in GitHub Desktop.
Save aryomuzakki/c995a537068b91cdbd9a7c8856b54bd5 to your computer and use it in GitHub Desktop.
Generate Secret Key with Node JS Crypto

script

require('crypto').randomBytes(64).toString('hex');
// 918fc5da09945d2f4086d2458f514bd4cacf6cab559174420f1e7d2caa8881edfdd78c417b9ad32b3c67a19ef4267bc50ff08cb913df158757b375c7f97371b6

require('crypto').randomBytes(64).toString('base64');
// hJNB4j5SI+mVxrvhoD/cSdHBMSFqWImEKlfWtMRVRSzoHp2uTSbixhBQ6iLaWtFK2mTENOUM6/mD2pD1ufgsAA==

require('crypto').randomBytes(64).toString('base64url');
// aMVKjWq3O0orHGddbW1HYQjD8hFeEtuH0Jrx80ZD0obT_wX8V9atgddDFMI3GS5InYbCoQAPVsMuzxGOJ_zi0g

command line

node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"

node -e "console.log(require('crypto').randomBytes(64).toString('base64'))"

node -e "console.log(require('crypto').randomBytes(64).toString('base64url'))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment