• The problem is actually with your node.js code :) If you look at what's in your buffer:

    > var s = String.fromCharCode(0x00,0x2B,0x20,0xFC);
    undefined
    > var b = new Buffer(s);
    undefined
    > b
    <Buffer 00 2b 20 c3 bc>
    > b.length
    5
    

    You'll see that it's magically turned the string into a 5 byte buffer. Most likely it's because it is interpreting your string as a UTF8 string, when I guess you intended to use it just as a string of bytes.

  • Yes.
    Just use 'ascii' to set the encoding format.

    Thanks a lot.

    > var s = String.fromCharCode(0x00,0x2B,0x20,0xFC);
    undefined
    > var b = new Buffer(s,'ascii');
    undefined
    > b
    <Buffer 00 2b 20 fc>
    > b.length
    4
    > b.toString('base64');
    'ACsg/A=='
    
About

Avatar for Gordon @Gordon started