DEV Community

Sanchit Gupta
Sanchit Gupta

Posted on

Base64 Encode and Decode in Javascript

See it in Action - https://www.apps4developers.com/base64

Converting Plain Text to Base64 Encoded String

btoa() generates a Base64 encoded ASCII string from plain text. This method is useful to encode text that is not in a URL-safe format.

Passing a string to btoa method will return a Base64 encoded string.

Example

btoa("Apps4Developers.com")
Enter fullscreen mode Exit fullscreen mode

---

Converting Base64 Encoded String to Plain Text

atob() method is used to convert Base64 encoded ASCII string to plain text.

Passing a Base64 encoded ASCII string to atob method will return plain text.

Example

atob("AkFwcHM0RGV2ZWxvcGVycy5jb20=")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)