Equivalent of OpenSSL base64 enc in Node.js (openssl enc -base64 -d -A)? -
there's api i'm working returns data that's gunzipped , double base64 encoded. i've tried using several of base64 libraries in npm no avail. doing each library's equivalent decodebase64(decodebase64(something))
fails due output encoding being faulty.
this work in shell: something | openssl enc -base64 -d -a | openssl enc -base64 -d -a | gunzip
. i'm looking node.js approach behaves same something | openssl enc -base64 -d -a | openssl enc -base64 -d -a | gunzip
.
the following libraries not work in situation: base64 base-64 js-base64
the solution find library can handle both string , binary representations of base64 (which mirrors openssl).
const forge = require('node-forge') const zlib = require('zlib') const pass1 = forge.util.decode64('sdrzsufbqufbqufbqunzcetrmezbstfnl1awrufbque=') const pass2 = forge.util.binary.base64.decode(pass1) const result = zlib.gunzipsync(new buffer(pass2)).tostring() console.log(result) // true
Comments
Post a Comment