Skip to content

Instantly share code, notes, and snippets.

@anonrig
Created February 11, 2019 21:11
Show Gist options
  • Save anonrig/3bbfc6549dd36b2d84fb151959678a46 to your computer and use it in GitHub Desktop.
Save anonrig/3bbfc6549dd36b2d84fb151959678a46 to your computer and use it in GitHub Desktop.
node.js aes example
const PromiseRouter = require('express-router-wrapper')
const router = new PromiseRouter()
const crypto = require('crypto')
const iv = process.env.VPN_AES_IV
const secret = process.env.VPN_AES_SECRET
router
.get('/', async (req, res) => {
const text = {key: "value"}
const cipher = crypto.createCipheriv(
'aes-256-cbc',
Buffer.from(secret),
Buffer.from(iv))
let encrypted = cipher.update(Buffer.from(text), 'utf8', 'hex')
encrypted += cipher.final('hex')
return {
data: encrypted.toString('hex')
}
})
module.exports = router.getOriginal()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment