Created
February 12, 2017 16:04
-
-
Save michaelO93/dbbe889976c9928ad1f94049d2c84b3c to your computer and use it in GitHub Desktop.
Triple3DES Algorithm implemented with 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
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