Skip to content

Instantly share code, notes, and snippets.

@michaelO93
Created February 12, 2017 16:04
Show Gist options
  • Save michaelO93/dbbe889976c9928ad1f94049d2c84b3c to your computer and use it in GitHub Desktop.
Save michaelO93/dbbe889976c9928ad1f94049d2c84b3c to your computer and use it in GitHub Desktop.
Triple3DES Algorithm implemented with Node.js
var CryptoJS = require('crypto-js');
var forge = require('node-forge');
var utf8 = require("utf8");
module.exports = {
encrypt: function (key, text) {
text = (text) ? text.toString() : '';
key = CryptoJS.MD5(utf8.encode(key)).toString(CryptoJS.enc.Latin1);
key = key + key.substring(0, 8);
var cipher = forge.cipher.createCipher('3DES-ECB', forge.util.createBuffer(key));
cipher.start({iv: ''});
cipher.update(forge.util.createBuffer(text, 'utf-8'));
cipher.finish();
var encrypted = cipher.output;
return ( forge.util.encode64(encrypted.getBytes()) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment