打赏

base64 编解码

使用浏览器内置的base64编码和解码的能力。

 

function utf8_to_b64( str ) {
  return window.btoa(unescape(encodeURIComponent( str )));
}

function b64_to_utf8( str ) {
  return decodeURIComponent(escape(window.atob( str )));
}

 

demo:

utf8_to_b64('✓ à la mode'); // "4pyTIMOgIGxhIG1vZGU="
b64_to_utf8('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode"

 

posted @ 2021-07-23 09:19  孟繁贵  阅读(81)  评论(0编辑  收藏  举报
TOP