JSBase64加密解密的介绍

复制代码代码如下所示:


无功base64encodechars =abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789 + / ;
无功base64decodechars =新的数组(
- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- -。
- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- 1,- -。
- 1,- 1,- 1,- 1,- 1,- 1,- 1, 63,- 1,- 1,- 1,- 1,- 1, 62,- -,
52, 53, 54,55, 56, 57,58, 59, 60,61,- 1,- 1,- 1,- 1,- 1,- 1,
- 1, 0, 1、2, 3, 4、5, 6, 7、8, 9, 10、11, 12, 13等。
15, 16, 17,18, 19, 20,21, 22, 23,24, 25,- 1,- 1,- 1,- 1,- 1,
- 1, 26, 27、28, 29, 30、31, 32, 33、34, 35, 36、37, 38, 39等。
41, 42, 43,44, 45, 46,47, 48, 49,50, 51,- 1,- 1,- 1,- 1,- 1);

功能Base64编码(STR){
var,我,莱恩;
var,C2,C3;
str.length len =;
我= 0;
out;
当(i){
C1 = str.charcodeat(i++)0xff;
如果(i = =){
= base64encodechars.charat(C1,2);
= base64encodechars.charat((C1 0x3)<4);
out;
打破;
}
C2 = str.charcodeat(我+ +);
如果(i = =){
= base64encodechars.charat(C1,2);
= base64encodechars.charat(((C1 0x3)> 4));
= base64encodechars.charat((C2 0xf)<2);
out;
打破;
}
C3 = str.charcodeat(我+ +);
= base64encodechars.charat(C1,2);
= base64encodechars.charat(((C1 0x3)> 4));
= base64encodechars.charat(((C2 0xf)> 6));
= base64encodechars.charat(C3 0x3f);
}
回来了;
}

功能base64decode(STR){
var,C2,C3,C4;
var I,莱恩,退出;

str.length len =;

我= 0;
out;
当(i){

{做
C1 = base64decodechars { str.charcodeat(i++)0xff };
}(i)= C1=1);
如果(C1 = 1)
打破;

{做
C2 = base64decodechars { str.charcodeat(i++)0xff };
}(i = C2 = - 1);
如果(C2 = 1)
打破;

(= String.fromCharCode(C1>4));

{做
C3 = str.charcodeat(i++)0xff;
如果(C3 = 61)
回来了;
base64decodechars C3 C3 = { };
}(i = C3 = - 1);
如果(C3 = 1)
打破;

= String.fromCharCode(((C2 0xf)> 2));

{做
C4 = str.charcodeat(i++)0xff;
如果(C4 = 61)
回来了;
base64decodechars C4 C4 = { };
}(i = C4 = 1);
如果(C4 = 1)
打破;
= String.fromCharCode(((C3 0x03)<6)| C4);
}
回来了;
}