base64 web前端js解码与转码

转载: https://blog.csdn.net/xieamy/article/details/78846732

编码,就是将字符串转化成base64 

    function b64EncodeUnicode(str) {
    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
        return String.fromCharCode('0x' + p1);
    }));

解码:就是将base64 转换成字符串

function b64DecodeUnicode(str) {
    return decodeURIComponent(atob(str).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
}

  

posted @ 2019-12-27 16:45  AloneInDefeat  阅读(2960)  评论(0编辑  收藏  举报