[Awesome Software CLI] Base64: Convert data as plain text in order to prevent data corruption
Base64
Base64 is the most popular binary-to-text algorithm used to convert data as plain text in order to prevent data corruption during transmission between different storage mediums. In addition, it is often used to embed binary data into text documents such as HTML, CSS, JavaScript, or XML. Given the high popularity of the algorithm, Base64 is well documented, is supported by various programming languages, has spawned several modifications, and, of course, has its own specification.
Base64 is most commonly used to encode binary data (for example, images, or sound files) for embedding into HTML, CSS, EML, and other text documents. In addition, Base64 is used to encode data that may be unsupported or damaged during transfer, storage, or output. Here are some of the applications of the algorithm:
-
Attach files when sending emails
-
Embed images in HTML or CSS via data URI
-
Preserve raw bytes of cryptographic functions
-
Output binary data as XML or JSON in API responses
-
Save binary files to database when BLOB is unavailable
-
Hide secrets from prying eyes (really a very bad idea)
Command Line Tool (CLI)
Installation
1 | macOS |
Commands
base64 help:
1 | base64 -h |
Encode and Decode:
1 | Encode |
Online Tool
Security
Base64 is not an encryption algorithm and in no case should it be used to “hash” passwords or “encrypt” sensitive data, because it is a reversible algorithm and the encoded data can be easily decoded. Base64 may only be used to encode raw result of a cryptographic function.
Roughly speaking, in terms of information security, Base64 is just a foreign language that some people do not understand. Nevertheless, even they can understand the meaning of the encoded message simply by using an online translator, which instantly returns the original message.
FAQs
base64: invalid input
A likely reason for 76 being the default is that Base64 encoding was to provide a way to include binary files in e-mails and Usenet postings which was intended for humans using monitors with 80 characters width. Having a 76-character width as default made that usecase easier.
-w, --wrap=COLS
will wrap encoded lines after COLS character (default 76). Use 0 to disable line wrapping.
For macOS, use -b, --break
to break encoded string into num character lines.
1 | echo cloudolife.com | base64 -w 0 |
References
[1] Base64 - Wikipedia - https://en.wikipedia.org/wiki/Base64
[2] Base64 - https://base64.guru/
[3] base64 — Homebrew Formulae - https://formulae.brew.sh/formula/base64
[4] command-not-found.com – base64 - https://command-not-found.com/base64
[5] Coreutils - GNU core utilities - https://gnu.org/software/coreutils
[6] Base64 Converter | Base64 - https://base64.guru/converter