前兩天看見有人問靜態網頁加密問題,就寫了這個代碼
思路:
加密時:先把用戶的密鑰A用md5加密為B,然後用B異或源文件S0得到目標文件S1,把S1存入js變量中。
解密時:詢問密鑰,然後操作同加密。
因為用了md5,個人認為沒有密鑰的時候是無法破解的(暴力除外)大家試用一下哈哈:
源代碼如下:
<html><head><title>Web Encoder</title><style>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;}</style><script>function webEncode(){ strSource=escape(XOR(t1.value,STR.md5(p1.value))); //strSource=t1.value; strOut="<script>\r\nstrHTML=\"\";\r\n"; for(var i=0;i+70<strSource.length;i+=70){ strOut+="strHTML+=\""+addSlash(strSource.substring(i,i+70))+"\";\r\n"; } strOut+="strHTML+=\""+addSlash(strSource.substring(i,strSource.length))+"\";\r\n"; strOut+=XOR+"\r\n"; //below code load the STR object strOut+="var STR =\r\n{\r\n\thexcase : 0, \/* hex output format. 0 - lowercase; 1 - "; strOut+="uppercase *\/\r\n\tb64pad : \"\", \/* base-64 pad character. \"=\" for "; strOut+="strict RFC compliance *\/\r\n\tchrsz : 8, \/* bits per input character"; strOut+=". 8 - ASCII; 16 - Unicode *\/\r\n\t\r\n\tb64_hmac_md5:\r\n\t\tfunction(key, "; strOut+="data) { return binl2b64(core_hmac_md5(key, data)); },\r\n\t\t\r\n\tb64_md5:\r\n"; strOut+="\t\tfunction(s){ return binl2b64(core_md5(str2binl(s), s.length * this.c"; strOut+="hrsz));},\r\n\t\t\r\n\tbinl2b64:\r\n\t\tfunction(binarray){\r\n\t\t var tab = \"ABCDE"; strOut+="FGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/\";\r\n\t\t var"; strOut+=" str = \"\";\r\n\t\t for(var i = 0; i < binarray.length * 4; i += 3)\r\n\t\t {"; strOut+="\r\n\t\t var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) "; strOut+="<< 16)\r\n\t\t | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & "; strOut+="0xFF) << 8 )\r\n\t\t | ((binarray[i+2 >> 2] >> 8 * ((i+2)%"; strOut+="4)) & 0xFF);\r\n\t\t for(var j = 0; j < 4; j++)\r\n\t\t {\r\n\t\t if(i "; strOut+="* 8 + j * 6 > 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 < binarray.length * 4; i++)\r\n\t\t {\r\n\t\t"; strOut+=" str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +\r\n\t\t"; strOut+=" hex_tab.charAt((binarray[i>>2] >&