Skip to content

Instantly share code, notes, and snippets.

@chjj
Created June 15, 2011 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chjj/1026954 to your computer and use it in GitHub Desktop.
Save chjj/1026954 to your computer and use it in GitHub Desktop.
base64 cipher fix
// 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