欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js加密(十)csti.cn md5

程序员文章站 2023-09-28 22:12:27
1. http://www.csti.cn/index.htm 2. 登录密码加密 3. 加密js: 1 var hexcase = 0; 2 var b64pad = ""; 3 var chrsz = 8; 4 function hex_md5(s) { 5 return binl2hex(co ......

1. 

2. 登录密码加密

3. 加密js:

  1 var hexcase = 0;
  2 var b64pad = "";
  3 var chrsz = 8;
  4 function hex_md5(s) {
  5 return binl2hex(core_md5(str2binl(s), s.length * chrsz));
  6 }
  7 function b64_md5(s) {
  8 return binl2b64(core_md5(str2binl(s), s.length * chrsz));
  9 }
 10 function str_md5(s) {
 11 return binl2str(core_md5(str2binl(s), s.length * chrsz));
 12 }
 13 function hex_hmac_md5(key, data) {
 14 return binl2hex(core_hmac_md5(key, data));
 15 }
 16 function b64_hmac_md5(key, data) {
 17 return binl2b64(core_hmac_md5(key, data));
 18 }
 19 function str_hmac_md5(key, data) {
 20 return binl2str(core_hmac_md5(key, data));
 21 }
 22 function md5_vm_test() {
 23 return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
 24 }
 25 function core_md5(x, len) {
 26 x[len >> 5] |= 0x80 << ((len) % 32);
 27 x[(((len + 64) >>> 9) << 4) + 14] = len;
 28 var a = 1732584193;
 29 var b = -271733879;
 30 var c = -1732584194;
 31 var d = 271733878;
 32 for (var i = 0; i < x.length; i += 16) {
 33     var olda = a;
 34     var oldb = b;
 35     var oldc = c;
 36     var oldd = d;
 37     a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
 38     d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
 39     c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
 40     b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
 41     a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
 42     d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
 43     c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
 44     b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
 45     a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
 46     d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
 47     c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
 48     b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
 49     a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
 50     d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
 51     c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
 52     b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
 53     a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
 54     d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
 55     c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
 56     b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
 57     a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
 58     d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
 59     c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
 60     b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
 61     a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
 62     d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
 63     c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
 64     b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
 65     a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
 66     d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
 67     c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
 68     b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
 69     a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
 70     d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
 71     c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
 72     b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
 73     a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
 74     d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
 75     c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
 76     b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
 77     a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
 78     d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
 79     c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
 80     b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
 81     a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
 82     d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
 83     c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
 84     b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
 85     a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
 86     d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
 87     c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
 88     b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
 89     a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
 90     d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
 91     c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
 92     b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
 93     a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
 94     d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
 95     c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
 96     b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
 97     a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
 98     d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
 99     c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
100     b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
101     a = safe_add(a, olda);
102     b = safe_add(b, oldb);
103     c = safe_add(c, oldc);
104     d = safe_add(d, oldd);
105 }
106 return array(a, b, c, d);
107 }
108 function md5_cmn(q, a, b, x, s, t) {
109 return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
110 }
111 function md5_ff(a, b, c, d, x, s, t) {
112 return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
113 }
114 function md5_gg(a, b, c, d, x, s, t) {
115 return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
116 }
117 function md5_hh(a, b, c, d, x, s, t) {
118 return md5_cmn(b ^ c ^ d, a, b, x, s, t);
119 }
120 function md5_ii(a, b, c, d, x, s, t) {
121 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
122 }
123 function core_hmac_md5(key, data) {
124 var bkey = str2binl(key);
125 if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
126 var ipad = array(16),
127 opad = array(16);
128 for (var i = 0; i < 16; i++) {
129     ipad[i] = bkey[i] ^ 0x36363636;
130     opad[i] = bkey[i] ^ 0x5c5c5c5c;
131 }
132 var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
133 return core_md5(opad.concat(hash), 512 + 128);
134 }
135 function safe_add(x, y) {
136 var lsw = (x & 0xffff) + (y & 0xffff);
137 var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
138 return (msw << 16) | (lsw & 0xffff);
139 }
140 function bit_rol(num, cnt) {
141 return (num << cnt) | (num >>> (32 - cnt));
142 }
143 function str2binl(str) {
144 var bin = array();
145 var mask = (1 << chrsz) - 1;
146 for (var i = 0; i < str.length * chrsz; i += chrsz) bin[i >> 5] |= (str.charcodeat(i / chrsz) & mask) << (i % 32);
147 return bin;
148 }
149 function binl2str(bin) {
150 var str = "";
151 var mask = (1 << chrsz) - 1;
152 for (var i = 0; i < bin.length * 32; i += chrsz) str += string.fromcharcode((bin[i >> 5] >>> (i % 32)) & mask);
153 return str;
154 }
155 function binl2hex(binarray) {
156 var hex_tab = hexcase ? "0123456789abcdef": "0123456789abcdef";
157 var str = "";
158 for (var i = 0; i < binarray.length * 4; i++) {
159     str += hex_tab.charat((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xf) + hex_tab.charat((binarray[i >> 2] >> ((i % 4) * 8)) & 0xf);
160 }
161 return str;
162 }
163 function binl2b64(binarray) {
164 var tab = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/";
165 var str = "";
166 for (var i = 0; i < binarray.length * 4; i += 3) {
167     var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xff) << 16) | (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xff) << 8) | ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xff);
168     for (var j = 0; j < 4; j++) {
169         if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
170         else str += tab.charat((triplet >> 6 * (3 - j)) & 0x3f);
171     }
172 }
173 return str;
174 }
175 
176 function tomd5str(s) {
177 var salt = "1#2$3%4(5)6@7!poeeww$3%4(5)djjkkldss";
178 return hex_md5(s + "{" + salt + "}");
179 }
180 
181 function getpwd(pwd) {
182 var login_salt = "973444";
183 return tomd5str(tomd5str(pwd) + login_salt);
184 }