base64编码和解码

来源:互联网 发布:实时大数据平台spark 编辑:程序博客网 时间:2024/05/21 07:06

base64编码和解码

base64编码

function b64EncodeUnicode(str) {    return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,        function toSolidBytes(match, p1) {            return String.fromCharCode('0x' + p1);    }));}b64EncodeUnicode('✓ à la mode'); // "4pyTIMOgIGxhIG1vZGU="b64EncodeUnicode('\n'); // "Cg=="

base64解码

function b64DecodeUnicode(str) {    return decodeURIComponent(atob(str).split('').map(function(c) {        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);    }).join(''));}b64DecodeUnicode('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode"b64DecodeUnicode('Cg=='); // "\n"

原文链接

原创粉丝点击