Base64 Encoding



Size

Warning: Our tools are server side tools, unless we stated otherwise. We do not keep or inspect the contents of the entered data in any way, and all communications with our servers are made through HTTPS (secured SSL). Regardless, we are strongly advise to avoid using sensitive data for our tools.

Provides Base64 encoding and decoding as defined by RFC 2045. This class implements section 6.8.Base64 Content-Transfer-Encoding from RFC 2045 Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies by Freed and Borenstein. The Base64 Alphabet contains 64 basic ASCII characters which are used to encode data. Yeah, that’s right, 64 characters is enough to encode any data of any length. The only drawback is that the size of the result will increase to 33%.

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The term Base64 originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.

Check here for Base64 Encode Explanation

or check our knowledgebase about Base64 encoding

While browsing some API documentation, I saw references to Base64 for passing credentials to the API. I had seen Base64 referenced a few times, but had no idea how to convert text into Base64. So, I did some digging. This post will outline how to encode (and decode) text into Base64 using the MacOS Terminal.

What is Base64?

I should share a little bit about what base64 is. The MDN documentation explains the overarching concept of Base64 is.

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.

Base64 Encode Username And Password

Base64 encoding example

You can think of Base64 is another way to represent binary or text data.

The conversion process is somewhat detailed, and I encourage you to check out the resources at the bottom of this article if you are curious about the benefits and technical details of Base64.

Converting Text into Base64

While reading those API docs, I had no idea to create a Base64 string.

There are converters a few Google searches away. But, did you know there’s a Base64 command built into the MacOS?

To turn a string into Base64, open a new Terminal window, and use this format.

That would be base64 followed by a space, three less-than signs (<), another space, then whatever string you want to encode in Base64.

Here’s an example:

Base64

If I wanted to convert the string I love cheeseburgers into Base64, I would enter this:

Which would print out SSBsb3ZlIGNoZWVzZWJ1cmdlcnMK as a result.

You only need quote marks around the string you would like to convert, if it has space it in.

The following does not need quote marks, for example:

Decoding Base64

With a similar command, you can decode Base64 back into human, readable text.

Let’s say a friend of ours sent us the following code:

SSBsb3ZlIHlvdSBtb3JlCg

To decode Base64, we add a -D flag before the three arrows and after base64.

Like this:

Base64 Encoding Characters

Which returns I love you more. How sweet!

Base64 is Not Unique

While a Base64 string like SSBsb3ZlIGNoZWVzZWJ1cmdlcnMk looks random, it is not.

Base64 Encoding Table

Each time I run base64 <<< 'I love cheeseburgers' it’ll return the same result. If you run the same code, you’ll get the same result. And since a Base64 string can be decoded, it’s not appropriate for hashing passwords, storing API keys, etc.

Base64 Encoding Tool

Resources