byte string to base64 javascript code example
Example 1: base64 to string and string to base64 javascript decode
let base64ToString = Buffer.from(obj, "base64").toString();
base64ToString = JSON.parse(base64ToString);
let str = 'bmltZXNoZGV1amEuY29t';
let buff = new Buffer(str, 'base64');
let base64ToStringNew = buff.toString('ascii');
let data = 'nimeshdeuja.com';
let buff = new Buffer(data);
let stringToBase64 = buff.toString('base64');
Example 2: convert base64 string to byte array javascript
Try this:
function _base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
return bytes.buffer;
}