

These JavaScript helper functions are named after old Unix commands for converting binary to ASCII (btoa) and ASCII to binary (atob).

To encode and decode in JavaScript, you will use the btoa() and atob() JavaScript functions that are available and supported by modern web browsers.
PURPOSE OF BASE64 ENCODING HOW TO
How to Encode and Decode HTML Base64 using JavaScript The resulting binary data is a reconstruction of the original binary data encoded to Base64. It takes a Base64 encoded string and maps each character back to its 6-bit binary representation. The result is a string of ASCII characters that can be transmitted or stored as text.īase64 decoding is the reverse process of encoding. The encoding process takes 3 bytes of binary data and maps it to 4 characters from the above set, such that a single character represents every 6 bits of binary data. The 64 characters used in Base64 encoding are: A-Z, a-z, 0-9, +, and /. It is commonly used to encode data that needs to be stored or transmitted in a way that cannot be directly represented as text.īase64 encoding works by mapping binary data to 64 characters from the ASCII character set. What is Base64?īase64 is a group of binary-to-text encoding schemes representing binary data in ASCII string format. In this article, you will learn about Base64 and how it works to convert binary data, regular strings, and lots more into ASCII text. This is possible thanks to two Base64 helper functions that are part of the HTML specification and are supported by all modern browsers. SQL>SELECT UTL_RAW.CAST_TO_VARCHAR2('41424344') FROM dual Ĭonclusion: So if we want to get encoded value as text instead of Hex we can use UTL_RAW.CAST_TO_VARCHAR2 which simply converts Hex to varchar2.When building an application or writing a program, you may need to encode or decode with HTML Base64 in JavaScript. Now in order to get my text back to original text 'ABCD', lets decode it. SQL>SELECT UTL_RAW.CAST_TO_RAW('QUJDRA=') FROM dual If we convert the ASCII value of these text into hex we get the encoded string returned by Base64 encoding. In order to get encoded string as text instead of RAW we can cast it to VARCHAR2. (Adds '=' sign to output text as we added 0s to make it 6bits)ĥ) Decimal representation of 6 bits representation of text.Ġ10000->16 010100->20 001001->9 000011->3 010001->17 000000->0Ħ) Now lets select from base64 characters(A-Z,a-z,0-9,+,/ altogether 64 characters:0-63) according to the decimal values.īut Oracle Base64 encoding returns this text as RAW(Hex Values). Let me explain how we have got this values according the encoding steps that i have mentioned above.ģ) Binary representation of text grouped by bytes.Ĥ1->01000001 42->01000010 43->01000011 44->01000100Ĥ) Bit representation of text grouped by 6 bits.

SQL> SELECT UTL_ENCODE.BASE64_ENCODE('41424344') FROM dual In Oracle we have got UTL_ENCODE package to encode it, which takes RAW and returns encoded value as RAW. We have got the hex values of 'ABCD' that is '41424344'.Ģ) Lets encode this hex using Base64. SQL> SELECT UTL_RAW.CAST_TO_RAW('ABCD') FROM dual Lets say we want to encode the text 'ABCD'.ġ) Lets convert this to RAW data which is hexadecimal values. Now i want to show this practically and also want to shows how the Oracle's Base64 encoding returns RAW value. So bit should be represented as 6 bits string.ĥ) Then these 6 bits string will be converted to decimal number.Ħ) Then it selects the ascii characters(A-Z,a-z,0-1,+ and /) according to the decimal number calculated in step 4.
PURPOSE OF BASE64 ENCODING 32 BIT
That is, it takes 24 bits of data and returns as 32 bit encoded characters. First of all I would like to tell how the Base64 works as general.Ģ) Converts it to Hexadecimal values(Decimal to Hex conversion).ģ) Represents the text in bits(groups as byte).Ĥ) Since the Base64 takes three bytes of data. It order to understand your problem and to simulate it I have generated one scenario.
