decode base64: invalid input

Solution 1:

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

Solution 2:

Or even more simply

base64 -di foo.zip > foo2.zip

Solution 3:

If you're doing this on a mac, your version of base64 might not have the flexibility to handle ignoring garbage. If you brew install coreutils, you'll have the gbase64 utility and use it as Joe has described.