https://blog.csdn.net/weixin_42193179/article/details/104932315
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js Base64.encode(str)_decode(str)</title> <script src="./lib/base64.js"></script> </head> <body> <script> /*参考:https://www.jianshu.com/p/14437764eff3*/ // 1.开源的 base64.js: https://github.com/dankogai/js-base64 let s1 = 'china is so nb'; let s2 = Base64.encode(s1); // 编码 console.log("s2:", s2); // s2: Y2hpbmEgaXMgc28gbmI= let s3 = Base64.decode(s2); // 解码 console.log("s3:", s3); // s3: china is so nb // 2.浏览器提供了原生的 Base64编码、解码方法 let s4 = window.btoa(s1); // 编码 console.log(" s4:", s4); //s4: Y2hpbmEgaXMgc28gbmI= let s5 = window.atob("Y2hpbmEgaXMgc28gbmI="); // 解码 console.log("s5:", s5); // s5: china is so nb </script> </body> </html>