JS Base64编码和解码

function b64Encode (str) {
    return btoa(encodeURIComponent(str));
}
function b64Decode (str) {
    return decodeURIComponent(atob(str));
}
var b = b64Encode('JavaScript 从入门到精通');
var a = b64Decode(b);
console.log(b);  //返回SmF2YVNjcmlwdCVFNCVCQiU4RSVFNSU4NSVBNFOSU5NyVBOCVFNSU4OCVCMCVFNyVCMiVCRSVFOSU4MCU5QQ==
console.log(a);  //返回“JavaScript 从入门到精通”