Skip to content

Instantly share code, notes, and snippets.

@getchenge
Created May 19, 2016 09:16

Revisions

  1. getchenge revised this gist May 19, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion aes.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    const crypto = require('crypto');
    const cryptor = {
    encrypt(cryptkey, iv, cleardata) {
    encrypt(cryptkey, iv, cleardata) {
    cryptkey = crypto.createHash('sha256').update(cryptkey).digest();
    const encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv);
    let encryptdata = encipher.update(cleardata, 'utf8', 'binary');
  2. getchenge created this gist May 19, 2016.
    18 changes: 18 additions & 0 deletions aes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    const crypto = require('crypto');
    const cryptor = {
    encrypt(cryptkey, iv, cleardata) {
    cryptkey = crypto.createHash('sha256').update(cryptkey).digest();
    const encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv);
    let encryptdata = encipher.update(cleardata, 'utf8', 'binary');
    encryptdata += encipher.final('binary');
    return new Buffer(encryptdata, 'binary').toString('base64');
    },
    decrypt(cryptkey, iv, encryptdata) {
    cryptkey = crypto.createHash('sha256').update(cryptkey).digest();
    encryptdata = new Buffer(encryptdata, 'base64').toString('binary');
    const decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv);
    let decoded = decipher.update(encryptdata, 'binary', 'utf8');
    decoded += decipher.final('utf8');
    return decoded;
    }
    }