首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码base64:输入无效

解码base64:输入无效
EN

Stack Overflow用户
提问于 2013-03-19 10:54:59
回答 4查看 77.3K关注 0票数 53

尝试在GNU/Linux上解码base64文件时,我得到"base64: invalid input“。

代码语言:javascript
复制
$ 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

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

我的base64版本:

代码语言:javascript
复制
$ 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.
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-03-19 11:00:26

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

一种解决方案:

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

备用项:

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

-i选项代表(在man页面中):

代码语言:javascript
复制
-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)
票数 98
EN

Stack Overflow用户

发布于 2019-12-20 07:36:02

或者更简单地说

base64 -di foo.zip > foo2.zip

票数 6
EN

Stack Overflow用户

发布于 2020-06-11 07:32:18

如果你在mac上做这件事,你的base64版本可能没有处理忽略垃圾的灵活性。如果您在brew中安装了coreutils,您将拥有gbase64实用程序,并按照乔的描述使用它。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15490728

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档