Skip to content

Instantly share code, notes, and snippets.

@RichAyotte
Created April 28, 2018 19:39
Show Gist options
  • Save RichAyotte/8519672bf3a94f152b5e4712791b5c7d to your computer and use it in GitHub Desktop.
Save RichAyotte/8519672bf3a94f152b5e4712791b5c7d to your computer and use it in GitHub Desktop.
Crypto helper module
/**
* @overview Crypto helper
* @author Richard Ayotte
* @copyright Copyright © 2018 Richard Ayotte
* @date 2018-04-27 17:52:01
* @license GNU GPL-3.0
* @flow
*/
'use strict'
const crypto = require('crypto')
const {algorithm, iv} = require('config').crypto
module.exports = {
decrypt({cipherText, key}) {
const decipher = crypto.createDecipheriv(algorithm, key, iv)
return decipher.update(cipherText, 'hex', 'utf8') + decipher.final('utf8')
}
, encrypt({text, key}) {
const cipher = crypto.createCipheriv(algorithm, key, iv)
return cipher.update(text, 'utf8', 'hex') + cipher.final('hex')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment