Created
February 11, 2019 21:11
-
-
Save anonrig/3bbfc6549dd36b2d84fb151959678a46 to your computer and use it in GitHub Desktop.
node.js aes example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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