Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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
You can’t perform that action at this time.