When getting a bas64 encoded string from the same input string I find that JavaScript, Groovy, and Go have the same result, but GNU base64 is slightly different. Why is that?
JavaScript (nodejs v0.10.33):
new Buffer('Laurence Tureaud is Mr. T').toString('base64');
TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVA==
Groovy (2.3.7 on Java 8):
'Laurence Tureaud is Mr. T'.bytes.encodeBase64().toString()
TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVA==
Go (1.4):
b64.StdEncoding.EncodeToString([]byte("Laurence Tureaud is Mr. T"))
TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVA==
GNU base64 (GNU coreutils 8.12.197-032bb with UTF-8 term charset):
echo 'Laurence Tureaud is Mr. T' | base64
TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVAo=
echo 'Laurence Tureaud is Mr. T'
Echo adds a newline after the string.
Try the following to remove the newline:
echo -n 'Laurence Tureaud is Mr. T' | base64
And you get TGF1cmVuY2UgVHVyZWF1ZCBpcyBNci4gVA==
All output is the same.
The only difference is that bash appends a newline () to the end when using
echo
. Therefore the is an additional character appended to the output (the character =
is only a padding in base64).