Javascript provides an easy way to Base64 encode and decode a string, using which we can encode decode a string to base64 on the fly.

Two functions window.btoa() & window.atob() can be used to achieve the task.


var encodedStr = window.btoa(“Hello world”); // to encode a string
var decodedStr = window.atob(encodedStr); // to decode the string

Consider the following Example:

Tested On: Chrome, Firefox, Internet Explorer (10),Safari

Online Demo Base64 Encode Decode String