Skip to content

Instantly share code, notes, and snippets.

@csanz
Created August 30, 2011 16:06

Revisions

  1. Christian Sanz revised this gist Aug 30, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion encrypt_decrypt.js
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,5 @@ var hw = encrypt("hello world")
    decrypt(hw)

    // feel free to change >> d6F3Efeq
    // To test just copy + paste the above inside the node shell
    // To test just copy + paste the above inside the node shell
    // TIP: always encrypt IDs before sending via HTTP
  2. Christian Sanz revised this gist Aug 30, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion encrypt_decrypt.js
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,4 @@ var hw = encrypt("hello world")
    decrypt(hw)

    // feel free to change >> d6F3Efeq
    // Just copy + paste the above inside the node shell
    // To test just copy + paste the above inside the node shell
  3. Christian Sanz revised this gist Aug 30, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion encrypt_decrypt.js
    Original file line number Diff line number Diff line change
    @@ -15,4 +15,5 @@ function decrypt(text){
    var hw = encrypt("hello world")
    decrypt(hw)

    // feel free to change >> d6F3Efeq
    // feel free to change >> d6F3Efeq
    // Just copy + paste the above inside the node shell
  4. Christian Sanz created this gist Aug 30, 2011.
    18 changes: 18 additions & 0 deletions encrypt_decrypt.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    function encrypt(text){
    var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
    var crypted = cipher.update(text,'utf8','hex')
    crypted += cipher.final('hex');
    return crypted;
    }

    function decrypt(text){
    var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
    var dec = decipher.update(text,'hex','utf8')
    dec += decipher.final('utf8');
    return dec;
    }

    var hw = encrypt("hello world")
    decrypt(hw)

    // feel free to change >> d6F3Efeq