js实现base64加密

解密

1
2
3
4
5
let b64EncodeUnicode = (str) => {//解密
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode('0x' + p1);
}))
}

加密

1
2
3
4
5
let b64DecodeUnicode = (str) => {//加密
return decodeURIComponent(atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}