2013-03-19 909 views
16

試圖解碼GNU/Linux上的base64文件,我得到「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 

我試過dos2unix命令,但它沒有幫助。

我的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. 
+0

至少在我的系統上,它是'-D'來解碼,而不是'-d'。 「base64 --help」在你的系統上說了些什麼? – 2013-03-19 02:58:34

+0

考慮升級;目前的版本至少爲8.20(2012年起),可能更近一些。 – 2013-03-19 03:03:30

+0

該版本是CentOS 5.x安裝的版本,因此根據誰控制環境,他可能沒有選擇。 – Joe 2013-03-19 04:07:31

回答

37

該版本將無法解碼(默認)有隔板的線條,但編碼器確實在默認情況下。 (較新的版本不存在這個問題。)

一個解決方案:

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

備選:

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

-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)