使用浏览器内置的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"

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-01-22
  • 2021-12-10
  • 2021-10-16
  • 2022-01-03
猜你喜欢
  • 2021-07-17
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案