Linux 解码 base64:无效输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15490728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:29:14  来源:igfitidea点击:

decode base64: invalid input

linuxshellbase64

提问by andyf

Trying to decode base64 file on GNU/Linux, I get "base64: invalid input".

尝试在 GNU/Linux 上解码 base64 文件,我得到“base64:无效输入”。

$ base64 test.zip | base64 -d > test2.zip
base64: invalid input
$ ll test*
-rw-r--r-- 1 user grp 152 19 11:41 test.zip
-rw-r--r-- 1 user grp  57 19 11:42 test2.zip

I tried dos2unixcommand, but it did not help.

我尝试了dos2unix命令,但没有帮助。

My base64 version:

我的 base64 版本:

$ base64 --version
base64 (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Simon Josefsson.

采纳答案by Joe

That version will not decode (by default) lines with separators, yet the encoder does that by default. (Newer versions don't have this problem.)

该版本不会解码(默认)带有分隔符的行,但编码器默认会这样做。(新版本没有这个问题。)

One solution:

一种解决方案:

base64 -w 0 foo.zip | base64 -d > foo2.zip

base64 -w 0 foo.zip | base64 -d > foo2.zip

Alternate:

备用:

base64 foo.zip | base64 -di > foo2.zip

base64 foo.zip | base64 -di > foo2.zip

The -ioption stands for (from the manpage):

-i选项代表(来自man页面):

-i, --ignore-garbage
       When decoding, ignore non-alphabet characters.
[...]
Decoding require compliant input by default, use --ignore-garbage to
attempt to recover from non-alphabet characters (such as newlines)

回答by Shawn Lillemo

Or even more simply

或者更简单

base64 -di foo.zip > foo2.zip

base64 -di foo.zip > foo2.zip