Skip to content

Instantly share code, notes, and snippets.

@hsorby
Last active February 25, 2021 23:12
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 hsorby/4a091a16f9851044742a5de593ba974b to your computer and use it in GitHub Desktop.
Save hsorby/4a091a16f9851044742a5de593ba974b to your computer and use it in GitHub Desktop.
Simple node script to encrypt a token for use with libCellML website.
// Instructions:
// Create a temporary directory and inside that directory install crypto-js.
// Then run the encrpyt.js script with node and pass your token as the first argument.
//
// Terminal commands:
// mkdir tmp
// cd tmp
// npm i crypto-js
// curl -o encrypt.js https://gist.githubusercontent.com/hsorby/4a091a16f9851044742a5de593ba974b/raw/587338203ce7b9dcc0baf0894f3d1d547a37a7a4/encrypt.js
// node encrypt.js <your-token>
//
// Clearly <your-token> should be replaced with a token generated from your Github account.
var CryptoJS = require('crypto-js')
const args = process.argv.slice(2)
if (args.length > 0) {
// Encrypt
const ciphertext = CryptoJS.AES.encrypt(args[0], 'public-key').toString()
// Decrypt
const bytes = CryptoJS.AES.decrypt(ciphertext, 'public-key')
const originalText = bytes.toString(CryptoJS.enc.Utf8)
console.log('original: ', originalText)
console.log('encrypted: ', ciphertext)
console.log()
console.log('Copy and paste the line below into your .env.local file:')
console.log(`VUE_APP_ENCRYPTED_GITHUB_TOKEN=${ciphertext}`)
} else {
console.log('Usage: node encrypt.js <token>')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment