Skip to content

Instantly share code, notes, and snippets.

@ejnshtein
Last active November 11, 2018 12:51
Show Gist options
  • Save ejnshtein/f3b44957dd23b5b3ade60ad6ad780b20 to your computer and use it in GitHub Desktop.
Save ejnshtein/f3b44957dd23b5b3ade60ad6ad780b20 to your computer and use it in GitHub Desktop.
const crypto = require('crypto')
const decrypt = (text, secret, algorithm = 'aes256') => {
const decipher = crypto.createDecipher(algorithm, secret)
let decrypted = decipher.update(text, 'hex', 'utf8')
decrypted += decipher.final('utf8')
return decrypted
}
///////////////////
// const crypto = require('crypto')
const encrypt = (text, secret, algorithm = 'aes256') => {
const cipher = crypto.createCipher(algorithm, secret)
let crypted = cipher.update(text, 'utf8', 'hex')
crypted += cipher.final('hex')
return crypted
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment