Skip to content

Instantly share code, notes, and snippets.

@dominykas
Created October 1, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dominykas/00631b8435927d96f75a to your computer and use it in GitHub Desktop.
Save dominykas/00631b8435927d96f75a to your computer and use it in GitHub Desktop.
var forge = require("node-forge");
function trimZeroes(data) {
return data.toString().replace(/^\0+/, "").replace(/\0+$/, "");
}
function tangoDecrypt(tangoHash, tangoSharedSecret) {
var decodedKey = new Buffer(tangoSharedSecret, "base64");
var ivSize = decodedKey.length;
var decodedHash = new Buffer(tangoHash.trim(), "base64");
var iv = forge.util.createBuffer(decodedHash.slice(0, ivSize).toString("binary"));
var data = forge.util.createBuffer(decodedHash.slice(ivSize).toString("binary"));
var decipher = forge.cipher.createDecipher("AES-CBC", decodedKey.toString("binary"));
decipher.start({
iv: iv
});
decipher.update(data);
decipher.finish();
return JSON.parse(trimZeroes(decipher.output));
}
module.exports = tangoDecrypt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment