Sample Header Ad - 728x90

Javascript BTOA vs base64 in bash?

4 votes
1 answer
3543 views
I need to convert a username and password combination into base64 before sending to an API. The javascript BTOA function is working for me, but when I try to use base64 command in bash I get slightly different results. **Javascript:** btoa("hello"); # aGVsbG8= btoa("username:password"); # dXNlcm5hbWU6cGFzc3dvcmQ= btoa("testing"); # dGVzdGluZw== **Bash:** echo hello | base64 # aGVsbG8K echo username:password | base64 # dXNlcm5hbWU6cGFzc3dvcmQK echo testing | base64 # dGVzdGluZwo= Results are always similar but different. Server expects the JS style encoding, but I need to use bash. Why are the results different but similar? How can I produce the results from javascript with bash?
Asked by Philip Kirkbride (10746 rep)
Aug 3, 2017, 02:40 PM
Last activity: Dec 6, 2023, 06:52 PM