Skip to content

Instantly share code, notes, and snippets.

@ndabAP
Created September 9, 2018 06:58
Show Gist options
  • Save ndabAP/94cd699b62e77658c4d50a31b9de6a4a to your computer and use it in GitHub Desktop.
Save ndabAP/94cd699b62e77658c4d50a31b9de6a4a to your computer and use it in GitHub Desktop.
En-/Decryption with Node.js
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