Created
October 1, 2015 11:09
-
-
Save dominykas/00631b8435927d96f75a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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