base64 web前端js解码与转码

来源:互联网 发布:拉圈圈网站源码 编辑:程序博客网 时间:2024/06/06 13:09

解码,就是把base64的转换成常规字符串

    function b64EncodeUnicode(str) {    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {        return String.fromCharCode('0x' + p1);    }));}b64EncodeUnicode('我是很厉害的'); // "5oiR5piv5b6I5Y6J5a6z55qE"

转码

function b64DecodeUnicode(str) {    return decodeURIComponent(atob(str).split('').map(function(c) {        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);    }).join(''));}b64DecodeUnicode('5oiR5piv5b6I5Y6J5a6z55qE'); // "我是很厉害的"
原创粉丝点击