1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| const Base64 = {
| //加密
| encode(str: any) {
| return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
| function toSolidBytes(match, p1) {
| return String.fromCharCode("0x" + p1);
| }));
| },
| //解密
| decode(str: any) {
| // Going backwards: from bytestream, to percent-encoding, to original string.
| return decodeURIComponent(atob(str).split("").map(function(c) {
| return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
| }).join(""));
| }
| };
| export default Base64;
|
|