Jan, 28 2022

Tools

Base 64 Encode/Decode

Base 64 decode and encode data to and from different formats.




Frequently Asked Questions

Base 64 refers to a way of encoding binary data in an ASCII text format. It is designed to carry binary data across channels. Base 64 converts any data into a long string of text. It is a representation of radix-64. Besides, it uses only6-bits to make data readable by humans. We can also write base78 or base65, but base64 can encode any strings.
We use base 64 when there is a need to encode data, store and transfer it over media designed for textual data. This ensures that your data remains intact during the transportation process. When encoding data to base 64, you have to start with a sequence of bytes then convert it into a string of text. Computers can only communicate in zeros and ones. However, people need to communicate with rich forms of data such as images and text. Hence this data needs to be converted into zeros and ones before its transmitted. A lot of encodings were introduced but had many shortcomings. Base 64 was introduced to solve these problems.
Base 64 encode means to convert binary data to text, especially for transferring or storing over media that users can handle. It is also known as privacy-enhanced Electronic mail, which is primarily used in the email encryption process. Apart from emails, base 64 encoding is used in storing complex data in JSON and XML. The choice of characters for base 64 can vary between implementations. But the general rule of trump when selecting the characters is to choose from part of the subset and make sure it's printable.

What is base 64 decode?

Base 64 decode is the opposite of base 64 encoding. Humans cannot read encoded data; hence, it must be decoded once it arrives at the media system. A decoder transforms the base 64 representation back to the original text or binary data format. If you have a piece of an odd-looking text string, then you will need a decoder to turn it into an ASCII string.
You can encode your data into base 64 in PHP using the base_64encode() function. It is an inbuilt function for encoding data using the MIMEbase64. Write the following syntax string base64_encode( $data ) in your code.This function accepts $data that specifies the string encoding and returns a base64 encoded string. In case of failure, then it returns false. If you want to decode a given data in PHP, then use the base64_decode() function. Replace the following syntax with your values: base64_decode ( string $string , bool $strict = false ) : string|false. The first argument stands for the data you want to decode. Next, the second argument checks if your data characters are not within the base 64 elements.

How to do base 64 in Javascript?

You can encode data to base64 in javascript using the btoa() function. First define your string using var decodedStringBtoA = '””; syntax. Then encode it using var encodedStringBtoA = btoa(decodedStringBtoA); Lastly display it using console.log(encodedStringBtoA); For example let's encode the word “helllo world” using javascript.

// Define the string
var decodedStringBtoA = 'Hello World!';

// Encode the String
var encodedStringBtoA = btoa(decodedStringBtoA);
console.log(encodedStringBtoA);

The output will be SGVsbG8gV29ybGQh

To decode data from base64 then we need to use the atob() function. Let's use the string that we have just encoded.

// Define the string
var encodedStringAtoB = 'SGVsbG8gV29ybGQh';

// Decode the String
var decodedStringAtoB = atob(encodedStringAtoB);
console.log(decodedStringAtoB);

The output will be Hello world!
Base64 produces a 33% larger output compared to its original size. This means that you cannot use it as a compression technique since you will require more storage space. In addition, Base64 results in more CPU usage because data takes longer to process. This means that it will slow down your website or application. Data URIs are not also supported on IE6 and IE.

Contact us, if you did not find the right answer or you have a other question?

Copyright 2018-2022 Anto Online.

Important Legal stuff:
Acceptable Use Policy | Disclaimer | Privacy Policy | Terms and Conditions.

All rights reserved. Please consider the information, scripts and instructions carefully
before using it yourself. Make sure you have ample backups! The information, scripts and
instructions are provided without warranty. Consult a professional if you are unsure.
Anto does not speak on behalf of any company and our opinions are our own.