A virtual teacher who reveals to you the great secrets of Base64

JavaScript Base64

JavaScript (abbreviated as JS) is a multi-paradigm programming language which supports object-oriented, imperative and functional styles. As well as HTML and CSS, JavaScript is most often used in web development (of course, it is not only limited to this). In addition to a huge number of features, it provides built-in functions to encode and decode data using the Base64 algorithm.

To encode data to Base64 in JavaScript, use the function btoa:

var b64 = btoa('guru');
console.log(b64); //-> "Z3VydQ=="

And of course, the reverse process — to decode Base64 values use the function atob:

var str = atob('Z3VydQ==');
console.log(str); //-> "guru"

Although there is nothing complicated about these functions, you should remember the following:

  1. Some old browsers don’t support JavaScript Base64 functions. This is why, be sure that you want to support only Chrome 4+, Edge 12+, Firefox 2+, Internet Explorer 10+, and Safari 3.1+, otherwise you must use a polyfill.

  2. As a rule, the built-in JavaScript Base64 functions will not be able to encode and decode Unicode strings. Therefore, if you need to support them you should apply some “hacks”.

  3. There are some objects that support methods for converting values to a Data URIs. Thanks to them, you can get Base64 values by simply removing the data URI prefix, which may be faster than using btoa.

To get a closer look at JavaScript Base64 functions, please consider the following examples:

Comments (35)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • funny,
    I can help you a problem.
    I want to load page on mobile

    object.iframe-view(style="height: 600px;" data=`data:application/pdf;base64,${dataPostRes.data.base64}`type="application/pdf")


    how to display it in mobile when responsive no display.
  • Suresh,
    Jawa script ling send me plz
  • ud1n_h0lmes,

    XOR DECRYPT

    import binascii
    from pwn import xor

    enc = binascii.unhexlify('202020202020120c531e2a531a2b05191b3d060c1b020a14')
    #print(enc)
    format_flag = "ITCLUB"

    key = xor(enc, format_flag)
    key = key[0:6]
    print(key)
    res = xor(enc, key)
    print(res)
  • nqhXncMU,
    -1" OR 2+163-163-1=0+0+0+1 --
  • nqhXncMU,
    -1; waitfor delay '0:0:15' --
  • nqhXncMU,
    0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
  • nqhXncMU,
    1
  • nqhXncMU,
    -5) OR 398=(SELECT 398 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -1); waitfor delay '0:0:15' --
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    (select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
  • nqhXncMU,
    -1" OR 2+711-711-1=0+0+0+1 --
  • nqhXncMU,
    R19W8pe6')) OR 483=(SELECT 483 FROM PG_SLEEP(15))--
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • gBqsPxAZ,
    -1); waitfor delay '0:0:15' --
  • gBqsPxAZ,
    -5 OR 520=(SELECT 520 FROM PG_SLEEP(15))--
  • gBqsPxAZ,
    if(now()=sysdate(),sleep(15),0)
  • gBqsPxAZ,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • gBqsPxAZ,
    -1 OR 2+600-600-1=0+0+0+1 --
  • nqhXncMU,
    -1' OR 2+697-697-1=0+0+0+1 or 'FPI5iFNF'='
  • nqhXncMU,
    0cAO531y' OR 400=(SELECT 400 FROM PG_SLEEP(15))--
  • nqhXncMU,
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • nqhXncMU,
    0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
  • nqhXncMU,
    555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
  • nqhXncMU,
    uQeKKbnh') OR 121=(SELECT 121 FROM PG_SLEEP(15))--
  • nqhXncMU,
    Yz9pPzwP') OR 954=(SELECT 954 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    1
  • ncMUFCMU,
    -1); waitfor delay '0:0:15' --
  • ncMUFCMU,
    -5 OR 97=(SELECT 97 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    tsV5R0pT') OR 829=(SELECT 829 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    -5 OR 957=(SELECT 957 FROM PG_SLEEP(15))--
  • nqhXncMU,
    if(now()=sysdate(),sleep(15),0)
  • nqhXncMU,
    mEVWa9uo')) OR 324=(SELECT 324 FROM PG_SLEEP(15))--
  • hiren,
    gfdgfdgfdgdgfdg
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.