// Custom function to encode a string to Base64 function base64Encode(str) { const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; let encoded = '', i = 0;
while (i < str.length) { const a = str.charCodeAt(i++); const b = i < str.length ? str.charCodeAt(i++) : 0; const c = i < str.length ? str.charCodeAt(i++) : 0;