2017-03-30

HOWTO: base64 manipulations in Linux

Do you want to decode some base64-encoded strings (or any other data), or convert some binary file to text (in base64)?
It's quite easy to do that in Debian GNU/Linux: base64 utility is a part of coreutils package (that package has a "required" priority, i. e., it's an essential package for the system to work).

When you finish typing your strings, don't forget to press <Enter> followed by <Ctrl> + <D> (or <Ctrl> + <D> twice, if you don't like newlines).
$ base64
Hello, world!
SGVsbG8sIHdvcmxkIQo=
$ 
$ base64 -d
SGVsbG8sIHdvcmxkIQo=
Hello, world!
But it may be safer to use file input-output, e. g.:
$ base64 -d in.txt > out.dat

References:
  1. man base64
  2. GNU Coreutils: base64 invocation
  3. Base64 - Wikipedia

See also: