Base64 转码

Base64 转码
btoa():任意值转为 Base64 编码
atob():Base64 编码转为原来的值

function b64Encode(str) {
  return btoa(encodeURIComponent(str));
}

function b64Decode(str) {
  return decodeURIComponent(atob(str));
}

b64Encode('你好') // "JUU0JUJEJUEwJUU1JUE1JUJE"
b64Decode('JUU0JUJEJUEwJUU1JUE1JUJE') // "你好"

 

posted @ 2024-01-10 16:24  谷粒-笔记  阅读(305)  评论(0)    收藏  举报