
For more details, see the documentation for btoa(). Note that btoa() expects to be passed binary data, and will throw an exception if the given string contains any characters whose UTF-16 representation occupies more than one byte. The algorithm used by atob() and btoa() is specified in RFC 4648, section 4. atob(): decodes a Base64-encoded string("atob" should be read as "ASCII to binary").btoa(): creates a Base64-encoded ASCII string from a "string" of binary data ("btoa" should be read as "binary to ASCII").Typically, Base64 encoding is used to encode binary data for. Binary data is represented as an ASCII string.
#Base64 encoding explained series#
In JavaScript there are two functions respectively for decoding and encoding Base64 strings: Base 64-encoding allows a binary file to be transmitted as a series of characters in a textual medium (for example, email or newsgroups). Base64 is a binary to text encoding scheme. It includes a table, base64, which contains two functions, encode() and decode() which, respectively.
#Base64 encoding explained code#
One common application of Base64 encoding on the web is to encode binary data so it can be included in a data: URL. The following code provides base64 encoding and decoding.

Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML. This is to ensure that the data remain intact without modification during transport. In computer programming, Base64 is a group of binary-to-text encoding schemes that represent binary data in sequences of 24 bits that can be represented by. The wiki article here goes into more details about the background of the. These strings must also be divisible by 4 to be well-formed. In contrast to encoding, hashing cannot be reversed. Hashing involves computing a fixed-length mathematical summary of data, the input data can be any size. The term Base64 originates from a specific MIME content transfer encoding.īase64 encoding schemes are commonly used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with ASCII. There are 64 characters in the Base64 alphabet, and an encoded string will contain a mixture of uppercase and lowercase letters, numbers, and sometimes an or two (never more than two) at the end. Take a scenario where a user wants to upload a resume to a job application website and the web server stores. 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.
