Created
April 12, 2018 04:12
-
-
Save eldoy/f7bcedddc5fefeb76bb250589d5e04cc to your computer and use it in GitHub Desktop.
This file contains 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
// Nodejs encryption with CTR | |
const crypto = require('crypto') | |
class Crypto { | |
constructor () { | |
this.algorithm = 'aes192' | |
this.secret = 'd6F3Efeq' | |
} | |
encrypt (text) { | |
let cipher = crypto.createCipher(this.algorithm, this.secret) | |
let crypted = cipher.update(text, 'utf8', 'hex') | |
crypted += cipher.final('hex') | |
return crypted | |
} | |
decrypt (text) { | |
let decipher = crypto.createDecipher(this.algorithm, this.secret) | |
let dec = decipher.update(text, 'hex', 'utf8') | |
dec += decipher.final('utf8') | |
return dec | |
} | |
} | |
const c = module.exports = new Crypto() | |
// DEMO: | |
let enc = c.encrypt('Hello') | |
console.log(enc) | |
let dec = c.decrypt(enc) | |
console.log(dec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment