Utilitarian Tools logo

Decode base64 to text

Encode

More About Base64

The term Base64 was originated by a specific MIME Type and it refers to a group of binary-to-text encodings to safely represent binary data in ASCII string format by translating into a radix-64 representation, it is aimed to be a transport format across systems that support only text-based communication.

That is one of the reasons why it is so popular on web development, and among other things it enables embedding binary assets like images into HTML web pages and CSS style sheets.

Note that base64 is by no means a compression algorithm the average size of the resulting string is 33% bigger than the original one and can be much bigger if the original is small, so when calculating the necessary size to store information in base64 consider this extra size.

For more detailed information on how it works, specifications, implementation, and history take a look at this article from Wikipedia

Example

Here is an example of what a normal string of text looks like when encoded to base64.

The original string:

Sample text

And the encoded string in base64:

U2FtcGxlIHRleHQ=

As mentioned before the resulting string is bigger than the original one.

Base64 in different programming languages

Since it is a popular method of transporting data, libraries to convert to and from base64 are widely available in basically all modern programming languages, here is a list of the most common:

PHP

Javascript

Python

FAQ

What is base64 used for?

Among other things it is used for:

  • Transport binary data as ASCII string
  • Transport or store strings that might have problems with limiter characters, like commas on a CSV
  • Embed binary data into HTML and CSS to avoid depending on external data using the Data URI scheme
  • Store binary data in string-based fields on databases
  • Compress multiple parameters into a single chunk of text facilitating the transportation
  • Pass API authentication headers, like for Basic access authentication

Why base64 completes with ==?

It does not always include == at the end of encoded strings, this process is called padding, and usually is not necessary to successfully decode the content, unless the encoded base64 string is concatenating multiple encoded files.

Learn more about padding here, and check out this great Stackoverflow thread

Is base64 safe?

From a data-security perspective, base64 is not safe, given the fact that anyone with access to the base64 string can easily decode back to plain text or binary and access all information.

From a data-store perspective yes, you will not lose information converting to and from base64.

How to display base64 images in HTML?

It is based on the data URI Scheme data:[media type][;base64],data

And you use this scheme on the src value of the image tag as the example below:

<img src="data:image/png; base64,base64String" />

We will soon have a base64 converter in Utilitarian tools.

© Utilitarian Tools - 2020