Last active
December 26, 2015 21:29
-
-
Save mpneuried/7215904 to your computer and use it in GitHub Desktop.
Simplify the data en/decryption in node.js
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 characters
### USEAGE | |
crypto = require( "./crypto" )() | |
_crypted = crypto.crypt( "myPassowrd", "data123" ) | |
crypto.decrypt( "myPassowrd", _crypted ) # data123 | |
### | |
crypto = require( "crypto" ) | |
module.exports = ( algorithm = "aes128", enc_in = "utf8", enc_out = "hex", padding = true )-> | |
_ret = | |
crypt: ( key, str )-> | |
cipher = crypto.createCipher( algorithm, new Buffer( key ) ) | |
cipher.setAutoPadding( padding ) | |
_cipher = cipher.update( str, enc_in, enc_out ) | |
_cipher += cipher.final( enc_out ) | |
return _cipher | |
decrypt: ( key, crypted )-> | |
decipher = crypto.createDecipher( algorithm, new Buffer( key ) ) | |
decipher.setAutoPadding( padding ) | |
_decipher = decipher.update( crypted, enc_out, enc_in ) | |
_decipher += decipher.final( enc_in ) | |
return _decipher | |
return _ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment