Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

base64 to string and string to base64 javascript decode

// base64 to string
let base64ToString = Buffer.from(obj, "base64").toString();
base64ToString = JSON.parse(base64ToString);

//or
let str = 'bmltZXNoZGV1amEuY29t';
let buff = new Buffer(str, 'base64');
let base64ToStringNew = buff.toString('ascii');

// string to base64
let data = 'nimeshdeuja.com';
let buff = new Buffer(data);
let stringToBase64 = buff.toString('base64');
Comment

js decode base64

let str = 'bmltZXNoZGV1amEuY29t';
let buff = new Buffer(str, 'base64');
let base64ToStringNew = buff.toString('utf8');
Comment

javascript base64 decode

// Define the string
var string = 'Hello World!';

// Encode the String
var encodedString = btoa(string);
console.log(encodedString); // Outputs: "SGVsbG8gV29ybGQh"

// Decode the String
var decodedString = atob(encodedString);
console.log(decodedString); // Outputs: "Hello World!"
Comment

javascript decode a sting in base64

const data = 'CodezUp';
console.log('---ORIGINAL-----', data)

// Encode String

const encode = Buffer.from(data).toString('base64')
console.log('
---ENCODED-----', encode)

// Decode String

const decode = Buffer.from(encode, 'base64').toString('utf-8')
console.log('
---DECODED-----', decode)
Comment

javascript encode base64

const encoded = window.btoa('Alireza Dezfoolian'); // encode a string
const decoded = window.atob(encoded); // decode the string
Comment

js base64 encoding

str = "The quick brown fox jumps over the lazy dog";
b64 = btoa(unescape(encodeURIComponent(str)));
str = decodeURIComponent(escape(window.atob(b64)));
Comment

javascript base64 decode

var decodedString = atob(encodedString);
Comment

base64 encode in javascript

const base64Encode = (string) => {
  const newText = btoa(string);
  return newText;
};
Comment

js base64 encode

function toBinary(string) {
  const codeUnits = new Uint16Array(string.length);
  for (let i = 0; i < codeUnits.length; i++) {
    codeUnits[i] = string.charCodeAt(i);
  }
  return String.fromCharCode(...new Uint8Array(codeUnits.buffer));
}

function fromBinary(binary) {
  const bytes = new Uint8Array(binary.length);
  for (let i = 0; i < bytes.length; i++) {
    bytes[i] = binary.charCodeAt(i);
  }
  return String.fromCharCode(...new Uint16Array(bytes.buffer));
}

const myString = "☸☹☺☻☼☾☿"
// console.log(btoa(myString)) // Error InvalidCharacterError: The string to be encoded contains characters outside of the Latin1 range.
const converted = toBinary(myString)
const encoded = btoa(converted)
console.log(encoded)

const decoded = atob(encoded)
const original = fromBinary(decoded)
console.log(original);
Comment

base64 in js

const Base64 = {
    _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    encode: function(input: string) {
        let output = "";
        let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        let i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },
    _utf8_encode: function(input: string) {
        input= input.replace(/
/g, "
");
        let utftext = "";

        for (let n = 0; n < input.length; n++) {

            let c = input.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

}


const encode = ( cipher : string) => {

    const encodedString: string = Base64.encode(cipher)

    return encodedString;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: ERR_REQUIRE_ESM 
Javascript :: import jsx file without extension 
Javascript :: filter falsy values js 
Javascript :: javascript scroll event 
Javascript :: react native class component constructor 
Javascript :: javascript get text between two strings 
Javascript :: js get anchor 
Javascript :: how to get file size in node js 
Javascript :: javascript get json keys 
Javascript :: jquery ajax while loading 
Javascript :: javascript number methods 
Javascript :: moment set hours 
Javascript :: nl2br in jquery 
Javascript :: verify if number is not floating 
Javascript :: react construct 
Javascript :: javascript last index 
Javascript :: javascript confirm delete 
Javascript :: strapi login api 
Javascript :: javascript log dom element 
Javascript :: React Redux reducer combineReducers exemple 
Javascript :: select element by data 
Javascript :: get last in array javascript 
Javascript :: mongodb filter empty array 
Javascript :: cross-origin request blocked the same origin policy disallows reading the remote resource fix in node js node js 
Javascript :: url decode in javascript 
Javascript :: vue router default page not loaded 
Javascript :: last element of an array javascript 
Javascript :: javascript add button to div 
Javascript :: datatable column width 
Javascript :: electron getPath 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =