Decode and Encode Base64 using Mac OSX terminal
Starting with version 10.8 Mac OSX ships with built-in utility base64.
Decoding Base64 string to text
$ echo -n "VGhpbmsgZGlmZmVyZW50" | base64 -D
> Think different
Encoding Base64 string
$ echo -n "Think different" | base64
> VGhpbmsgZGlmZmVyZW50
Note that without -n parameter echo will produce a string with a new-line character added to its end.
You also have an option to use pbpaste utility which basically returns contents of your clipboard:
$ pbpaste | base64
> VGhpbmsgZGlmZmVyZW50
Encoding Base64 string from file
base64 utility supports encoding binary files:
$ base64 -i icon.svg
> PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6...
You might want to copy the result of encoding into your clipboard without need to manually select the resulting string with use of pbcopy command:
$ base64 -i icon.svg | pbcopy