前端用base64加密和解密的使用方法,只需要两个函数就可以了。一个是加密:window.btoa(),一个是解密:window.atob(),看例子:
<html>
<head>
<title>前端的base64使用方法</title>
</head>
<body>
前端的base64使用方法
</body>
<script>
var str = "hello";
var str64 = window.btoa("hello");
console.log("字符串是:"+str);
console.log("经base64编码后:"+str64);
console.log("base64解码后:"+window.atob(str64));
</script>
</html>
测试结果: