Skip to content

Instantly share code, notes, and snippets.

@chjj chjj/base64fix.js
Created Jun 15, 2011

Embed
What would you like to do?
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
You can’t perform that action at this time.