Thursday, August 31, 2017

Base64 encoding and decoding(btoa & atob)

Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.

In JavaScript there are two functions respectively for decoding and encoding base64 strings:
atob()
btoa()

In these APIs, for mnemonic purposes, the "b" can be considered to stand for "binary", and the "a" for "ASCII"

The atob() function decodes a string of data which has been encoded using base-64 encoding.

Conversely, the btoa() function creates a base-64 encoded ASCII string from a "string" of binary data.

Both atob() and btoa() work on strings

Syntax
var encodedData = scope.btoa(stringToEncode);

Parameters
stringToEncode
A string whose characters each represent a single byte of binary data to be encoded into ASCII.
Return value
A string containing the Base64 representation of stringToEncode.

Example

var encodedData = window.btoa('Hello, world'); // encode a string
var decodedData = window.atob(encodedData); // decode the string

No comments:

Change default Port on Next.js app

 If any other app or process is running on port 3000 , you will get this error in your terminal Port 3000 is already in use. error Command f...