10 examples of 'jquery base64 encode' in JavaScript

Every line of 'jquery base64 encode' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
55function base64_encode(str) {
56 const utf8str = unescape(encodeURIComponent(str));
57 return base64_encode_data(utf8str, utf8str.length, b64c);
58}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

338function base64encode(array) {
339 return btoa(String.fromCharCode(...array));
340}
61function base64encode(data) {
62 return btoa(data.replace(/[\u0100-\uffff]/g, function(c) {
63 return String.fromCharCode(c.charCodeAt(0) & 0xff);
64 }));
65}
1function base64_encode (data) {
2 // discuss at: http://phpjs.org/functions/base64_encode/
3 // original by: Tyler Akins (http://rumkin.com)
4 // improved by: Bayron Guevara
5 // improved by: Thunder.m
6 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
7 // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
8 // improved by: Rafał Kukawski (http://blog.kukawski.pl)
9 // bugfixed by: Pellentesque Malesuada
10 // example 1: base64_encode('Kevin van Zonneveld');
11 // returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
12 // example 2: base64_encode('a');
13 // returns 2: 'YQ=='
14 // example 3: base64_encode('✓ à la mode');
15 // returns 3: '4pyTIMOgIGxhIG1vZGU='
16
17 var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
18 var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
19 ac = 0,
20 enc = '',
21 tmp_arr = []
22
23 if (!data) {
24 return data
25 }
26
27 data = unescape(encodeURIComponent(data))
28
29 do {
30 // pack three octets into four hexets
31 o1 = data.charCodeAt(i++)
32 o2 = data.charCodeAt(i++)
33 o3 = data.charCodeAt(i++)
34
35 bits = o1 << 16 | o2 << 8 | o3
36
37 h1 = bits >> 18 & 0x3f
38 h2 = bits >> 12 & 0x3f
39 h3 = bits >> 6 & 0x3f
40 h4 = bits & 0x3f
41
42 // use hexets to index into b64, and append result to encoded string
43 tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4)
44 } while (i < data.length)
45
46 enc = tmp_arr.join('')
47
48 var r = data.length % 3
49
50 return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3)
51}
18_b64_encode: function base64_encode(data) {
19 // http://kevin.vanzonneveld.net
20 // + original by: Tyler Akins (http://rumkin.com)
21 // + improved by: Bayron Guevara
22 // + improved by: Thunder.m
23 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
24 // + bugfixed by: Pellentesque Malesuada
25 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
26 // + improved by: Rafał Kukawski (http://kukawski.pl)
27 // * example 1: base64_encode('Kevin van Zonneveld');
28 // * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
29 // mozilla has this native
30 // - but breaks in 2.0.0.12!
31 //if (typeof this.window['atob'] == 'function') {
32 // return atob(data);
33 //}
34 var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
35 "abcdefghijklmnopqrstuvwxyz0123456789+/=";
36 var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
37 ac = 0,
38 enc = "",
39 tmp_arr = [];
40
41 if (!data) {
42 return data;
43 }
44
45 do { // pack three octets into four hexets
46 o1 = data.charCodeAt(i++);
47 o2 = data.charCodeAt(i++);
48 o3 = data.charCodeAt(i++);
49
50 bits = o1 << 16 | o2 << 8 | o3;
51
52 h1 = bits >> 18 & 0x3f;
53 h2 = bits >> 12 & 0x3f;
54 h3 = bits >> 6 & 0x3f;
55 h4 = bits & 0x3f;
56
57 // use hexets to index into b64, and append result to encoded string
58 tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
59 } while (i < data.length);
60
61 enc = tmp_arr.join('');
62
63 var r = data.length % 3;
64
65 return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
66
67},
28function base64(s) {
29 return window.btoa(s).split('=')[0]
30}
10function base64_encode(data) {
11 var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
12 var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
13 ac = 0,
14 enc = '',
15 tmp_arr = [];
16
17 if (!data) {
18 return data;
19 }
20
21 do { // pack three octets into four hexets
22 o1 = data.charCodeAt(i++);
23 o2 = data.charCodeAt(i++);
24 o3 = data.charCodeAt(i++);
25
26 bits = o1 << 16 | o2 << 8 | o3;
27
28 h1 = bits >> 18 & 0x3f;
29 h2 = bits >> 12 & 0x3f;
30 h3 = bits >> 6 & 0x3f;
31 h4 = bits & 0x3f;
32
33 // use hexets to index into b64, and append result to encoded string
34 tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
35 } while (i < data.length);
36
37 enc = tmp_arr.join('');
38
39 var r = data.length % 3;
40
41 return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
42}
64function base64url_encode(str) {
65 const utf8str = unescape(encodeURIComponent(str));
66 return base64_encode_data(utf8str, utf8str.length, b64u);
67}
229function base64_encode (s) {
230 // the result/encoded string, the padding string, and the pad count
231 var r = "";
232 var p = "";
233 var c = s.length % 3;
234
235 // add a right zero pad to make this string a multiple of 3 characters
236 if (c > 0) {
237 c = 3 - c;
238 var ns = new Uint8Array(s.length + c);
239 ns.set(s);
240
241 for (var i = 0; i < c; i++) {
242 p += '=';
243 ns.set[s.length + i] = 0;
244 }
245
246 s = ns;
247 }
248
249 // increment over the length of the string, three characters at a time
250 for (c = 0; c < s.length; c += 3) {
251
252 // we add newlines after every 76 output characters, according to the MIME specs
253 if (c > 0 && (c / 3 * 4) % 76 == 0) {
254 r += "\r\n";
255 }
256
257 // these three 8-bit (ASCII) characters become one 24-bit number
258 var n = (s[c] << 16) + (s[c+1] << 8) + s[c+2];
259
260 // this 24-bit number gets separated into four 6-bit numbers
261 n = [(n >>> 18) & 63, (n >>> 12) & 63, (n >>> 6) & 63, n & 63];
262
263 // those four 6-bit numbers are used as indices into the base64 character list
264 r += base64chars[n[0]] + base64chars[n[1]] + base64chars[n[2]] + base64chars[n[3]];
265 }
266 // add the actual padding string, after removing the zero pad
267 return r.substring(0, r.length - p.length) + p;
268}
65function b64_encode(data) {
66 var o1, o2, o3, h1, h2, h3, h4, bits, r, i = 0, enc = "";
67 if (!data) { return data; }
68 do {
69 o1 = data[i++];
70 o2 = data[i++];
71 o3 = data[i++];
72 bits = o1 << 16 | o2 << 8 | o3;
73 h1 = bits >> 18 & 0x3f;
74 h2 = bits >> 12 & 0x3f;
75 h3 = bits >> 6 & 0x3f;
76 h4 = bits & 0x3f;
77 enc += b64_table.charAt(h1) + b64_table.charAt(h2) + b64_table.charAt(h3) + b64_table.charAt(h4);
78 } while (i < data.length);
79 r = data.length % 3;
80 return (r ? enc.slice(0, r - 3) : enc) + "===".slice(r || 3);
81}

Related snippets