Why do the following produce different output?
echo Chris | openssl base64 // Q2hyaXMK
new Buffer('Chris').toString('base64') // Q2hyaXM=
I'm trying to use the passport-http library for Basic authentication, and it appears to be expecting encoded data in the format of #1. This is a problem for me as all my tests rely on node for generating encoded data (mocha, supertest). Any help is greatly appreciated.
The difference is that the echo command appends a linefeed character at the end of the text it's supposed to output.
In other words, the Base64 encoding for Chris is actually Q2hyaXM=, but the representation of Chris\n (where \n is not a literal \ followed by a literal n but just a linefeed character) is Q2hyaXMK indeed. You might want to compare with:
new Buffer('Chris\n')
In order to compare with the result of your command ;)