Created
June 15, 2011 12:07
-
-
Save chjj/1026954 to your computer and use it in GitHub Desktop.
base64 cipher fix
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
// a shim to fix base64 cipher output, untested | |
var Cipher = require('crypto').Cipher; | |
var update = Cipher.prototype.update, | |
final = Cipher.prototype.final; | |
Cipher.prototype.update = function(data, input, output) { | |
if (output === 'base64') { | |
data = update.call(this, data, input, 'binary'); | |
return new Buffer(data, 'binary').toString('base64'); | |
} | |
return update.apply(this, arguments); | |
}; | |
Cipher.prototype.final = function(output) { | |
if (output === 'base64') { | |
var data = final.call(this, 'binary'); | |
if (!data) return data; | |
return new Buffer(data, 'binary').toString('base64'); | |
} | |
return final.apply(this, arguments); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment