[英]decode base64: invalid input
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 dos2unix command, 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.
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
Alternate:备用:
base64 foo.zip | base64 -di > foo2.zip
The -i
option stands for (from the man
page): -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)
或者更简单
base64 -di foo.zip > foo2.zip
If you're doing this on a mac, your version of base64
might not have the flexibility to handle ignoring garbage.如果您在 Mac 上执行此操作,则您的base64
版本可能无法灵活处理忽略垃圾。 If you brew install coreutils
, you'll have the gbase64
utility and use it as Joe has described.如果您 brew install coreutils
,您将拥有gbase64
实用程序并按照 Joe 的描述使用它。
You can also try using您也可以尝试使用
echo -n
to suppress new lines and padding the input length to a multiple of 4 with one to three equal characters抑制换行并将输入长度填充为 4 的倍数,并使用一到三个相同的字符
=
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.