静态网页加密
前两天看见有人问静态网页加密问题,就写了这个代码
稍微有些长,解释一下思路:
加密时:先把用户的密钥A用md5加密为B,然后用B异或源文件S0得到目标文件S1,把S1存入js变量中。
解密时:询问密钥,然后操作同加密。
因为用了md5,个人认为没有密钥的时候是无法破解的(暴力除外)
大家试用一下
Web Encoder
body {
font-size:12px;
line-height:12px;
background-Color:buttonface;
border-width:0px;
overflow:auto;
margin:0px;
padding:4px;
}
#t1, #t2 {
width:100%;
height:40%;
border-width:1px;
overflow:auto;
height:expression((document.body.clientHeight-100)/2);
}
input {
border-width:1px;
padding-left:10px;
padding-right:10px;
margin:4px;
}
function webEncode(){
strSource=escape(XOR(t1.value,STR.md5(p1.value)));
//strSource=t1.value;
strOut="\r\nstrHTML=\"\";\r\n";
for(var i=0;i+70> 2] >> 8 * ( i %4)) & 0xFF) ";
strOut+="> 2] >> 8 * ((i+1)%4)) & ";
strOut+="0xFF) > 2] >> 8 * ((i+2)%";
strOut+="4)) & 0xFF);\r\n\t\t for(var j = 0; j binarray.length * 32) str += this.b64pad;\r\n\t\t else ";
strOut+="str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);\r\n\t\t }\r\n\t\t }\r\n\t\t r";
strOut+="eturn str;\r\n\t\t},\r\n\t\t\r\n\tbinl2hex:\r\n\t\tfunction(binarray){\r\n\t\t var hex_t";
strOut+="ab = this.hexcase ? \"0123456789ABCDEF\" : \"0123456789abcdef\";\r\n\t\t var ";
strOut+="str = \"\";\r\n\t\t for(var i = 0; i >2] >> ((i%4)*8+4)) & 0xF) +\r\n\t\t";
strOut+=" hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);\r\n\t\t ";
strOut+=" }\r\n\t\t return str;\r\n\t\t},\r\n\t\r\n\tbinl2str:\r\n\t\tfunction(bin){\r\n\t\t var st";
strOut+="r = \"\";\r\n\t\t var mask = (1 >5] >>> (i % 32)) & mask);\r\n\t\t return str;\r\n\t\t},\r\n\t\t\r\n\tbit_rol:";
strOut+="\r\n\t\tfunction(num, cnt){return (num >> (32 - cnt));},\r\n";
strOut+="\t\t\r\n\tcore_hmac_md5:\r\n\t\tfunction(key, data){\r\n\t\t var bkey = str2binl(k";
strOut+="ey);\r\n\t\t if(bkey.length > 16) bkey = core_md5(bkey, key.length * this";
strOut+=".chrsz);\r\n\t\t\r\n\t\t var ipad = Array(16), opad = Array(16);\r\n\t\t for(var";
strOut+=" i = 0; i > 5] |= 0x80 ";
strOut+=">> 9) >";
strOut+=" 16) + (y >> 16) + (lsw >> 16);\r\n\t\t return (msw >5] |= (str.charCodeAt(i";
strOut+=" \/ this.chrsz) & mask) ";
t2.value=strOut;
}
function runCode(){
win=open("about:blank");
win.document.write(t2.value);
win.document.close();
}
function addSlash(str){
return(str).replace(/\\/g,"\\\\").replace(/\//g,"\\\/").replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\"/g,"\\\"").replace(/\'/g,"\\\'").replace(/\t/g,"\\t");
}
function XOR(strV,strPass){
var intPassLength=strPass.length;
var re="";
for(var i=0;i
strAskPass+="Password:";
strAskPass+="
";
document.write(strAskPass);
}
var STR =
{
hexcase : 0, /* hex output format. 0 - lowercase; 1 - uppercase */
b64pad : "", /* base-64 pad character. "=" for strict RFC compliance */
chrsz : 8, /* bits per input character. 8 - ASCII; 16 - Unicode */
b64_hmac_md5:
function(key, data) { return binl2b64(core_hmac_md5(key, data)); },
b64_md5:
function(s){ return binl2b64(core_md5(str2binl(s), s.length * this.chrsz));},
binl2b64:
function(binarray){
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for(var i = 0; i > 2] >> 8 * ( i %4)) & 0xFF) > 2] >> 8 * ((i+1)%4)) & 0xFF) > 2] >> 8 * ((i+2)%4)) & 0xFF);
for(var j = 0; j binarray.length * 32) str += this.b64pad;
else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
}
}
return str;
},
binl2hex:
function(binarray){
var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i >2] >> ((i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
}
return str;
},
binl2str:
function(bin){
var str = "";
var mask = (1 >5] >>> (i % 32)) & mask);
return str;
},
bit_rol:
function(num, cnt){return (num >> (32 - cnt));},
core_hmac_md5:
function(key, data){
var bkey = str2binl(key);
if(bkey.length > 16) bkey = core_md5(bkey, key.length * this.chrsz);
var ipad = Array(16), opad = Array(16);
for(var i = 0; i > 5] |= 0x80 >> 9) > 16) + (y >> 16) + (lsw >> 16);
return (msw >5] |= (str.charCodeAt(i / this.chrsz) & mask)
Source:
Password:
Encoded:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]