Base64 is an encoding and decoding algorithm. We need the encoding of some data in order to prevent storing and transmission problems. For example, If we try to transfer binary data it may create and affect some network devices because of its data structures. Base64 is generally used different applications like email and MIME, XML, JSON, URL, and HTTP, etc.
Base64 uses alphabet, numbers and
= for encoded data. For example, the following examples are valid Base64 encoded data
And following are not valid encoded data
Base64 Is Not Encryption
Base64 is just encoding format so it is not used to encrypt data to hide from third parties. Base64 encoded data can be easily reverted or decoded back to the text format. It can work two way without a security restriction of password.
Now we will look some examples about to encrypt and decrypt Base64 in Linux bash environment.
We will encode file contents named
base64 command. We do not provide any option for this.
$ base64 data.txt
Decoding is very similar to encode we will just provide
-d option to the
base64 command like below. In this example, we will use a file named
encoded.txt which contains base64 encoded data.
$ base64 -d encoded.txt
atob() functions which are a short form of
binary to ascii and
ascii to binary . We will just provide the text or data we want to convert to these functions like below.
//Encode atob("Test"); //Decode btoa("VGVzdAo=")
In PHP Programming language we can use
base64_decode functions like below.
//Encoding base64_encode("Test"); //Decode base64_decode("VGVzdAo=")