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:
-
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.
-
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”.
-
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 (36)
I hope you enjoy this discussion. In any case, I ask you to join it.
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.
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)