Created
April 28, 2018 19:39
-
-
Save RichAyotte/8519672bf3a94f152b5e4712791b5c7d to your computer and use it in GitHub Desktop.
Crypto helper module
This file contains hidden or 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
/** | |
* @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