Base64 Encode and Decode String Online

Some of the links are affiliate links and I earn commission from them. Moreover, as an Amazon Associate, I earn from qualifying purchases.

Do you want to store any string or text secretly, so that no one can read the actual text? Well, an easy way to do that is to use base64 to encode and decode the encoded string with base64 whenever you want to read it.

In this post, we have an online convertor using which you can encode a string with Base64. Additionally, you can use another convertor tool to decode the same string.

What Is Base64 encode and decode?

Base 64 is an encoding scheme that takes binary information and changes it into complex text by translating the data to a radix-64 representation. The reversal process is called decode.

The below table shows the binary data and its respective base64 character.

BinaryCharBinaryCharBinaryCharBinaryChar
000000A010000Q100000g110000w
000001B010001R100001h110001x
000010C010010S100010i110010y
000011D010011T100011j110011z
000100E010100U100100k1101000
000101F010101V100101l1101011
000110G010110W100110m1101102
000111H010111X100111n1101113
001000I011000Y101000o1110004
001001J011001Z101001p1110015
001010K011010a101010q1110106
001011L011011b101011r1110117
001100M011100c101100s1111008
001101N011101d101101t1111019
001110O011110e101110u111110+
001111P011111f101111v111111/
Padding =

How To Use Base64 encode decode in Programming Language

You can use the above tool base64 encoding and decoding without having knowledge of programming language. However, the below section describes the code you can use to encode and decode base64.

Base64 Encode In JavaScript

Javascript is a very popular language. In fact, the above Base64 encoder and decoder are built with Javascript only. In javascript, you can use window.btoa(“string”) to encode a string in Base64 whereas to decode you can use window.atob(“string”).

<input type="textarea" name="inputtext" id="encode">
<button onclick="myFunction1()">Encode Base64</button>
<br>
<input type="textarea" name="inputtext" id="decode">
<button onclick="myFunction2()">Decode Base64</button>

<p id="demo1"></p>
<p id="demo2"></p>

<script>
function myFunction1() {
  var str = document.getElementById("encode").value;
  var enc = window.btoa(str);

  var res = "Encoded String: " + enc;
  document.getElementById("demo1").innerHTML = "The original string: " + str + "<br>" + res;
}

function myFunction2() {
  var str = document.getElementById("decode").value;
  var enc = window.atob(str);

  var res = "Encoded String: " + enc;
  document.getElementById("demo2").innerHTML = "The original string: " + str + "<br>" + res;
}
</script>

Encode and Decode String With Base64 using Python

Python has an inbuilt library called Base64 for encoding and decoding strings. First, you have to import the library, convert the strings to byte-like objects, and then encode it using the base64 library. Follow the exact reverse process to decode the strings.


>>> import base64
>>> string = "techieblogging"
>>> string_bytes = string.encode("ascii")
>>> base64_bytes = base64.b64encode(string_bytes)
>>> 
>>> base64_string = base64_bytes.decode("ascii")
>>> print(f"Encoded string: {base64_string}")
Output: Encoded string: dGVjaGllYmxvZ2dpbmc=
>>> #decoding string
>>> base64_string ="dGVjaGllYmxvZ2dpbmc="
>>> base64_bytes = base64_string.encode("ascii")
>>> string_bytes = base64.b64decode(base64_bytes)
>>> string = string_bytes.decode("ascii")
>>> print(f"Decoded string: {string}")
Output: Decoded string: techieblogging
>>> 

Base64 encoding and Decoding using PHP

In this post, we will see the PHP code using which you can encode and decode a string using base64. Like many programming languages, PHP has inbuilt libraries to perform encoding and decoding. In PHP language you perform base64 encode using base64_encode(“string”). Similarly, you can use base64_decode(“string”) to decode an encoded string.

<!DOCTYPE html>
<html>
<body>
<?php

// PHP code to encode strings

$str = 'techieblogging';
echo base64_encode($str);
?>

<?php
// PHP code to decode strings

$str = 'dGVjaGllYmxvZ2dpbmc=';

echo base64_decode($str);
?> 

</body>
</html>

What is the use of base64 encoding?

There are various ways you can use base64 encoding. One of the widely used scenarios is sending email attachments over email. The email software usually converts the attachment into a base64 encoded string and sends it over communication channels.

You can also use this approach to store confidential data. Though it is not powerful as encryption, still a better approach to store confidential data such as user name and password.

Conclusion

I Hope, the online base64 encoder and decoder will be useful to you in your day-to-day activities. Though it is not a replacement for encryption still a good approach for many cases.

If you feel any improvement is necessary, feel free to tell us in the comment section.

Visit Home Page
0 0 votes
Rate Us
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Web Hosting + Free Domain At $1.2/mo Use Coupon Code SOLARRAID85Click Here
+ +
0
Would love your thoughts, please comment.x
()
x