Sunny-117/js-challenges

用代码实现把字符串转换成base64编码

Sunny-117 opened this issue · 2 comments

用代码实现把字符串转换成base64编码
function encode(str){
    const encodestr = encodeURI(str);
    const base64 = btoa(encodestr);
    return base64;
}
function strToBase64(str) {
      str = encodeURI(str);
      return btoa(str);
}
function base64ToStr(base64) {
      base64 = atob(base64);
      return decodeURI(base64);
}