Base64

[cc lang=”javascript”]

var base64Encode = function(e) {
return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g, function(e, t) {
return String.fromCharCode(“0x” + t)
}))
};
var base64Decode= function(e) {
return decodeURIComponent(atob(e).split(“”).map(function(e) {
return “%” + (“00” + e.charCodeAt(0).toString(16)).slice(-2)
}).join(“”))
};
var urlBase64ToUint8Array = function(e) {
for (var t = “=”.repeat((4 – e.length % 4) % 4), n = (e + t).replace(/\-/g, “+”).replace(/_/g, “/”), r = atob(n), i = new Uint8Array(r.length), o = 0; o < r.length; ++o) i[o] = r.charCodeAt(o); return i; } [/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *