diff --git a/lib/xmlenc.js b/lib/xmlenc.js index 4eb04fb..e02e3d0 100644 --- a/lib/xmlenc.js +++ b/lib/xmlenc.js @@ -136,11 +136,11 @@ function decrypt(xml, options, callback) { switch (encryptionAlgorithm) { case 'http://www.w3.org/2001/04/xmlenc#aes128-cbc': - return callback(null, decryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, encrypted)); + return decryptWithAlgorithm('aes-128-cbc', symmetricKey, 16, encrypted, callback); case 'http://www.w3.org/2001/04/xmlenc#aes256-cbc': - return callback(null, decryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, encrypted)); + return decryptWithAlgorithm('aes-256-cbc', symmetricKey, 16, encrypted, callback); case 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc': - return callback(null, decryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, encrypted)); + return decryptWithAlgorithm('des-ede3-cbc', symmetricKey, 8, encrypted, callback); default: return callback(new Error('encryption algorithm ' + encryptionAlgorithm + ' not supported')); } @@ -205,7 +205,7 @@ function encryptWithAlgorithm(algorithm, symmetricKey, ivLength, content, encodi }); } -function decryptWithAlgorithm(algorithm, symmetricKey, ivLength, content) { +function decryptWithAlgorithm(algorithm, symmetricKey, ivLength, content, callback) { var decipher = crypto.createDecipheriv(algorithm, symmetricKey, content.slice(0,ivLength)); decipher.setAutoPadding(false); @@ -216,11 +216,10 @@ function decryptWithAlgorithm(algorithm, symmetricKey, ivLength, content) { if (1 <= padding && padding <= ivLength) { decrypted = decrypted.substr(0, decrypted.length - padding); } else { - callback(new Error('padding length invalid')); - return; + return callback(new Error('padding length invalid')); } - return new Buffer(decrypted, 'binary').toString('utf8'); + return callback(null, new Buffer(decrypted, 'binary').toString('utf8')); } exports = module.exports = {