base64编解码的使用
base64编码
base64 file
功能:从指定的文件file中读取数据,编码为base64的字符串然后输出;
echo “string” | base64
功能:将字符串string+换行编码为base64的字符串然后输出;
echo -n “string” | base64
功能:将字符串string编码为base64的字符串然后输出;
base64解码
base64 -d file
功能:从指定的文件file中读取已经过base64编码的数据,然后进行解码,并输出解码后的字符串;
echo “str” | base64 -d
功能:对base64编码的字符串str和空行进行解码,然后将解码后的字符串输出;
echo -n “str” | base -d
功能:对base64编码的字符串str进行解码,然后将解码后的字符串输出;
注意
在Ubuntu下base64解码时键入的是-d,而在mac上解码时键入的是-D;
具体情况可以在相应的平台键入下面的指令进行查看:
➜ ~ base64 --help
Usage: base64 [OPTION]... [FILE]
Base64 encode or decode FILE, or standard input, to standard output.
Mandatory arguments to long options are mandatory for short options too.
-d, --decode decode data
-i, --ignore-garbage when decoding, ignore non-alphabet characters
-w, --wrap=COLS wrap encoded lines after COLS character (default 76).
Use 0 to disable line wrapping
--help display this help and exit
--version output version information and exit
With no FILE, or when FILE is -, read standard input.
The data are encoded as described for the base64 alphabet in RFC 3548.
When decoding, the input may contain newlines in addition to the bytes of
the formal base64 alphabet. Use --ignore-garbage to attempt to recover
from any other non-alphabet bytes in the encoded stream.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'base64 invocation'