Last active
May 2, 2018 18:59
-
-
Save theodorosidmar/080128f974bbc865efac4f8660e7a45d to your computer and use it in GitHub Desktop.
Encrypt and decrypt texts to hexadecimal
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
| const crypto = require('crypto') | |
| const algorithm = 'aes-128-cbc' | |
| const key = Buffer.from('5ebe2294ecd0e0f08eab7690d2a6ee69', 'hex') | |
| const iv = Buffer.from('26ae5cc854e36b6bdfca366848dea6bb', 'hex') | |
| exports.encrypt = (text) => { | |
| const cipher = crypto.createCipheriv(algorithm, key, iv) | |
| let crypted = cipher.update(text, 'utf8', 'hex') | |
| crypted += cipher.final('hex') | |
| return crypted | |
| } | |
| exports.decrypt = (text) => { | |
| const decipher = crypto.createDecipheriv(algorithm, key, iv) | |
| let decrypted = decipher.update(text, 'hex', 'utf8') | |
| decrypted += decipher.final('utf8') | |
| return decrypted | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment