what are the differences between PHP base64_encode and *nix base64 what are the differences between PHP base64_encode and *nix base64 php php

what are the differences between PHP base64_encode and *nix base64


echo usually outputs a new line character at the end of the string, to suppress that use the -n switch:

$ echo -n 'test' | base64dGVzdA==

Similarly for PHP:

$ php<?phpecho base64_encode("test\n");?>dGVzdAo=


open console in your browser, type atob('dGVzdAo='):


(source: gyazo.com)

You have extra character in your input. And that is 0x0A (LF).


When doing an echo it gives me this:

MacPro:~ bardiir$ echo 'test'testMacPro:~ bardiir$ 

I'd guess you might have an included line-ending in the unix one as echo is probably appending a newline character even if you pipe it throuch to the base64 encode.