快速解码base64和utf-8的ASCII编码和URL解码

看论坛上总是有人发乱七八糟的文字,根本看不懂,用下面的方法解密一下.

只要有浏览器的开发者工具就行了.

UTF-16解码

console.log("\u5475\u5475")

 

URL解码(在ES6中被标记为Draft)

unescape("%u5475%u5475")

 

Base64解码

decodeURIComponent(escape(atob( "5ZG15ZG1=" )));

 

使用函数:

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

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

 

base64加解码库:

https://github.com/dankogai/js-base64

加解码说明:

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding

posted @ 2015-04-15 15:01  yantze  阅读(1893)  评论(0编辑  收藏  举报