Created
May 19, 2016 09:16
Revisions
-
getchenge revised this gist
May 19, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ 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'); -
getchenge created this gist
May 19, 2016 .There are no files selected for viewing
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 charactersOriginal 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; } }