Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

base64 command on macOS returns wrong result

When calling base64 <<< username:password I get this result: dXNlcm5hbWU6cGFzc3dvcmQK.

When using that result in PostMan and issuing a request against a Basic Auth endpoint, I get back a 401.

When encoding username:password at https://www.base64encode.org, I get back this result: dXNlcm5hbWU6cGFzc3dvcmQ= and I can successfully use it against the Basic Auth endpoint from above.

If I use PostMan to generate the Basic Auth header passing in username and password, it generates the same base64 encoded string as https://www.base64encode.org. I could also copy username:password into testin.txt and use openssl to create the base64 string:

openssl base64 -in testin.txt -out testout.txt returns dXNlcm5hbWU6cGFzc3dvcmQK which is the same wrong result as base64 creates.

openssl version returns OpenSSL 0.9.8zh 14 Jan 2016

like image 665
Alexander Zeitler Avatar asked Dec 16 '16 17:12

Alexander Zeitler


1 Answers

Decoding dXNlcm5hbWU6cGFzc3dvcmQK gives username:password\n.

So my guess is that in both cases, you have a linefeed you weren't expecting. The testin.txt case is easy to solve (modify file, remove linefeed).

I expect the base64 case can be solved by using echo with the -n parameter to remove the linefeed:

echo -n username:password | base64 --encode
like image 88
Joel Rondeau Avatar answered Sep 23 '22 14:09

Joel Rondeau