Search code examples
stringbashmacosencodingbase64

Why is base64 encoding my file on a Mac not resulting in a proper base64 string?


I'm using Mac OS 10.13.3. I'm trying to base64 encode a binary file but am having some issues. Specifically, I thought all base64 encoded files have to have a length that is a multiple of 4. However, when I encode my file, notice taht the length is not divisible by 4 ...

localhost:lib davea$ openssl base64 -in myfile.binary -out ~/Downloads/myfile.base64
localhost:lib davea$ ls -al ~/Downloads/myfile.base64 
-rw-r--r-- 1 davea staff 93162 May 31 14:22 /Users/davea/Downloads/myfile.base64

Also when I look at the contents of the base64 file, I don't see the traditional "=" or "==" at the end, which usually indicates padding

localhost:lib davea$ cat ~/Downloads/myfile.base64
...
C9vgMjoKSQYkXMLTrGKRleR558g3bY3VTqlsVvTqZXquCLp4JS4cprTG6N10H0u9
i4pwPrVmSAP2DmE1V7mGwR2e4fiYEWnZjpSbHofpzlUo34yhiQ2/5kJoQZktD7BU
uxYBAgQIECBAgBs2

Am I doing something wrong, or is there another way to base64 encode my file?


Solution

  • OK. I believe we were over thinking this quite a bit. Here is what you are looking for to get the desired behavior:

    openssl base64 -A -in myfile.binary -out ~/Downloads/myfile.base64

    This will convert to base64 without any line endings. The -A option is what does the trick.