base64 encode/decode

Macにおいて表題を実施する。

■ 環境

  • Mac OSX El Capitan

■ base64

Macには`base64`コマンドが存在する。

$ which base64
/usr/bin/base64
$
$ base64 --help
Usage:    base64 [-dhvD] [-b num] [-i in_file] [-o out_file]
  -h, --help     display this message
  -D, --decode   decodes input
  -b, --break    break encoded string into num character lines
  -i, --input    input file (default: "-" for stdin)
  -o, --output   output file (default: "-" for stdout)
$

■ encode

文字列”withsin“を”encode“してみる。

$ echo -n "withsin" | base64
d2l0aHNpbg==
$

■ decode

前述の”encode“で取得できた文字列を”decode“する。

$ echo "d2l0aHNpbg==" | base64 -D
withsin$

最後の改行を”encode“時に含んでいないので、”decode“は改行されなかった。

以上。