Skip to content

Instantly share code, notes, and snippets.

@mpede
mpede / Test
Created December 10, 2014 15:57
Test
Tsgt
@mpede
mpede / AESnode.js
Last active August 29, 2015 14:08
simple AES encryption class for node - you can pass key and iv or it will create them - you can change them after object creation as well
var AES=function(key,iv){
this.rc=function(l){ l=l||16;
var text = "", possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for(var i=0;i<l;i++) text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
this.iv =iv ||this.rc();
this.key=key||this.rc(128);
this.decrypt = function(encryptdata) {
var decipher = crypto.createDecipheriv('aes-256-cbc', crypto.createHash('sha256').update(this.key).digest(), this.iv);