Created
September 9, 2018 06:58
-
-
Save ndabAP/94cd699b62e77658c4d50a31b9de6a4a to your computer and use it in GitHub Desktop.
En-/Decryption with Node.js
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
import crypto from 'crypto' | |
const HASH = crypto.createHash('md5').update('password', 'utf-8').digest('hex') | |
export const encrypt = decrypted => { | |
let iv = new Buffer.alloc(16) | |
let cipher = crypto.createCipheriv('aes-256-cbc', HASH, iv) | |
return cipher.update(decrypted, 'utf8', 'hex') + cipher.final('hex') | |
} | |
export const decrypt = encrypted => { | |
let iv = new Buffer.alloc(16) | |
let decipher = crypto.createDecipheriv('aes-256-cbc', HASH, iv) | |
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment