-
• #2
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.
-
• #3
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=='
in nodejs terminal:
string is String.fromCharCode(0x00,0x2B,0x20,0xFC) , the base64 string is "ACsgw7w="
and in Espruino Web IDE left-hand terminal:
string is String.fromCharCode(0x00,0x2B,0x20,0xFC) , the base64 string is "ACsg/A=="
Why the same string gets different base64 encoded string in Espruino and nodejs?