ntkobackground.min.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /**
  2. * version: 1.7.5
  3. * number:002
  4. * 2020.04.16版本 跟随 产品发送
  5. */
  6. "use strict";
  7. var varNtkoGUID = Math.random().toString(36);
  8. var ntkoWinOpen=["ntkoWinOpen1","ntkoWinOpen2","ntkoWinOpen3","ntkoWinOpen4","ntkoWinOpen5","ntkoWinOpen6","ntkoWinOpen7","ntkoWinOpen8","ntkoWinOpen9","ntkoWinOpen10","ntkoWinOpen11","ntkoWinOpen12"];
  9. var ntkoList=[];
  10. var ntkoJsonIe;
  11. var timer;
  12. var ntkoSendDataToChildStrUrl;
  13. var ntkoSendDataToChildSData;
  14. var ntkowin;
  15. var userAgent = navigator.userAgent,
  16. rMsie = /(msie\s|trident.*rv:)([\w.]+)/,
  17. rFirefox = /(firefox)\/([\w.]+)/,
  18. rOpera = /(opera).+versi1on\/([\w.]+)/,
  19. rChrome = /(chrome)\/([\w.]+)/,
  20. rEdge = /(edg)\/([\w.]+)/,
  21. rSafari = /version\/([\w.]+).*(safari)/;
  22. var browser;
  23. var version;
  24. var ua = userAgent.toLowerCase();
  25. function uaMatch(ua) {
  26. var match = rMsie.exec(ua);
  27. if (match != null) {
  28. return { browser : "IE", version : match[2] || "0" };
  29. }
  30. var match = rFirefox.exec(ua);
  31. if (match != null) {
  32. return { browser : match[1] || "", version : match[2] || "0" };
  33. }
  34. var match = rOpera.exec(ua);
  35. if (match != null) {
  36. return { browser : match[1] || "", version : match[2] || "0" };
  37. }
  38. var match = rChrome.exec(ua);
  39. if (match != null) {
  40. var matchedge= rEdge.exec(ua);
  41. if(matchedge!=null){
  42. return { browser : matchedge[1] || "", version : matchedge[2] || "0" };
  43. }else{
  44. return { browser : match[1] || "", version : match[2] || "0" };
  45. }
  46. }
  47. var match = rSafari.exec(ua);
  48. if (match != null) {
  49. return { browser : match[2] || "", version : match[1] || "0" };
  50. }
  51. if (match != null) {
  52. return { browser : "", version : "0" };
  53. }
  54. }
  55. var browserMatch = uaMatch(userAgent.toLowerCase());
  56. if (browserMatch.browser) {
  57. browser = browserMatch.browser;
  58. version = browserMatch.version;
  59. }
  60. var mimeTypes = navigator.mimeTypes;
  61. var bChromeExtensionInstalled = false;
  62. if( "chrome" === browserMatch.browser && version>="45")
  63. {
  64. var img;
  65. img = new Image();
  66. img.src = "chrome-extension://lppkeogbkjlmmbjenbogdndlgmpiddda/icons/ntko.png";
  67. img.onload = function() {
  68. bChromeExtensionInstalled = true;
  69. };
  70. img.onerror = function() {
  71. bChromeExtensionInstalled = false;
  72. };
  73. }
  74. if("edg"===browserMatch.browser){
  75. var img;
  76. img = new Image();
  77. img.src = "chrome-extension://nldmejlecnngjgcfpinfkdhkfakjeail/icons/ntko.png";
  78. img.onload = function() {
  79. bChromeExtensionInstalled = true;
  80. };
  81. img.onerror = function() {
  82. bChromeExtensionInstalled = false;
  83. };
  84. }
  85. var ntkoBrowser = {
  86. init:function()
  87. {
  88. if(browser=="IE"){
  89. return true;
  90. }
  91. },
  92. ntkoSendDataToChild:function( strURL, data)
  93. {
  94. if ( typeof data === 'undefined' ){
  95. return;
  96. }
  97. var strURL=ntkoBrowser.NtkoStrURL(strURL);
  98. var jsonValue = '{"SendDataToChild":1,"GUID":"';
  99. jsonValue += varNtkoGUID;
  100. jsonValue += '","URLMD5":"';
  101. jsonValue += b64_md5(strURL);
  102. jsonValue += '","ChildValue":"';
  103. jsonValue += data;
  104. jsonValue += '"}';
  105. var ntkobr=ntkoBrowser.NtkoBrower();
  106. if(ntkobr){
  107. window.postMessage({ type: "FROM_NTKO_PAGE", text: jsonValue }, "*");
  108. }else{
  109. ntkowin=b64_md5(strURL);
  110. for(var i=0;i<ntkoList.length;i++){
  111. var ntkoiename=JSON.parse(ntkoList[i]);
  112. if(ntkoiename.name==ntkowin){
  113. try{
  114. var ab=ntkoiename.ntkosize;
  115. ntkoWinOpen[ab].location.href
  116. ntkoWinOpen[ab].ntkoGetParentData(data);
  117. }catch(e){
  118. }
  119. }
  120. }
  121. }
  122. },
  123. ExtensionInstalled:function()
  124. {
  125. var ntkobr=ntkoBrowser.NtkoBrower();
  126. if(!ntkobr){
  127. if(browser=="IE"){
  128. var ntkoarray=["NTKO.OfficeControl20160_X64","NTKO.OfficeControl20160","NTKO.OfficeControl20161_X64","NTKO.OfficeControl20161","NTKO.OfficeControlQiYe","NTKO.AttachManage","NTKO.OfficeControlQiYe20162","NTKO.OfficeControlQiYe20162_X64","NTKO.OfficeControl20162","NTKO.OfficeControl20162_X64"];
  129. for(var i=0;i<ntkoarray.length;i++){
  130. try{
  131. var ntkoobject=new ActiveXObject(ntkoarray[i]);
  132. return true;
  133. }catch(e){
  134. }
  135. }
  136. return false;
  137. }else{
  138. var mimetype=navigator.mimeTypes["application/ntko-plug"];
  139. if(mimetype){
  140. var plugin=mimetype.enabledPlugin;
  141. if(plugin){
  142. return true;
  143. }else{
  144. return false;
  145. }
  146. }else{
  147. return false;
  148. }
  149. }
  150. }
  151. else
  152. {
  153. if( "firefox" === browserMatch.browser )
  154. {
  155. var bInstalled = false;
  156. if( "undefined" === typeof FirefoxInstalled )
  157. return ( bInstalled );
  158. else
  159. return( window.FirefoxInstalled());
  160. }
  161. else if( "chrome" === browserMatch.browser )
  162. {
  163. return( bChromeExtensionInstalled );
  164. } else if("edg" === browserMatch.browser){
  165. return( bChromeExtensionInstalled );
  166. }
  167. }
  168. },
  169. ntkoClose:function( strURL )
  170. {
  171. var strURL=ntkoBrowser.NtkoStrURL(strURL);
  172. var jsonValue = '{"Close":1,"GUID":"';
  173. jsonValue += varNtkoGUID;
  174. jsonValue += '","URLMD5":"';
  175. jsonValue += b64_md5(strURL);
  176. jsonValue += '"}';
  177. var ntkobr=ntkoBrowser.NtkoBrower();
  178. if(ntkobr){
  179. window.postMessage({ type: "FROM_NTKO_PAGE", text: jsonValue }, "*");
  180. }else{
  181. ntkowin=b64_md5(strURL);
  182. for(var i=0;i<ntkoList.length;i++){
  183. var ntkoiename=JSON.parse(ntkoList[i]);
  184. if(ntkoiename.name==ntkowin){
  185. try{
  186. var ab=ntkoiename.ntkosize;
  187. ntkoWinOpen[ab].location.href
  188. ntkoWinOpen[ab].close();
  189. }catch(e){
  190. }
  191. }
  192. }
  193. }
  194. },
  195. openWindow:function( strURL,IsShowOnExtendMonitor,ProductCaption, ntkoBrowserProductKey, ntkoBrowserNoExpireKey, ntkoBrowserOptions,varUrlData )
  196. {
  197. if(varUrlData!=null&&varUrlData!=""){
  198. ntkoSendDataToChildSData=varUrlData;
  199. }
  200. var strURL=ntkoBrowser.NtkoStrURL(strURL);
  201. var jsonValue = '{"OpenWindow":1,"URL":"';
  202. jsonValue += strURL;
  203. jsonValue += '","GUID":"';
  204. jsonValue += varNtkoGUID;
  205. jsonValue += '","URLMD5":"';
  206. jsonValue +=b64_md5(strURL);
  207. jsonValue += '","IsShowOnExtendMonitor":"';
  208. jsonValue += IsShowOnExtendMonitor;
  209. jsonValue += '"';
  210. if( ( typeof ProductCaption != 'undefined' ) && ( ( null != ProductCaption ) && ( "" != ProductCaption ) ) )
  211. {
  212. jsonValue += ',"ProductCaption":"';
  213. jsonValue += ProductCaption;
  214. jsonValue += '"';
  215. }
  216. if( ( typeof ntkoBrowserProductKey != 'undefined' ) && ( ( null != ntkoBrowserProductKey ) && ( "" != ntkoBrowserProductKey ) ) )
  217. {
  218. jsonValue += ',"ProductKey":"';
  219. jsonValue += ntkoBrowserProductKey;
  220. jsonValue += '"';
  221. }
  222. if( ( typeof ntkoBrowserNoExpireKey != 'undefined' ) && ( ( null != ntkoBrowserNoExpireKey ) &&( "" != ntkoBrowserNoExpireKey ) ) )
  223. {
  224. jsonValue += ',"NoExpireKey":"';
  225. jsonValue += ntkoBrowserNoExpireKey;
  226. jsonValue += '"';
  227. }
  228. if( typeof ntkoBrowserOptions != 'undefined' && ( ( null != ntkoBrowserOptions ) && ( "" != ntkoBrowserOptions ) ) )
  229. {
  230. jsonValue += ',"Options":"';
  231. jsonValue += ntkoBrowserOptions;
  232. jsonValue += '"';
  233. }
  234. var LocalStorge = window.localStorage;
  235. if( typeof LocalStorge != 'undefined' && ( 0 != LocalStorge.length ) )
  236. {
  237. var varLocalDataList = [];
  238. for( var i = 0; i < LocalStorge.length; i++ )
  239. {
  240. var varLocalData = {};
  241. varLocalData["StorageKey"] = LocalStorge.key(i);
  242. varLocalData["StorageValue"] = LocalStorge.getItem(LocalStorge.key(i));
  243. varLocalDataList[i] = varLocalData;
  244. }
  245. jsonValue += ',"LocalStorge":';
  246. jsonValue += JSON.stringify(varLocalDataList);;
  247. jsonValue += '';
  248. }
  249. var SessionStorge = window.sessionStorage;
  250. if( typeof SessionStorge != 'undefined' && ( 0 != SessionStorge.length ) )
  251. {
  252. var varSessionDataList = [];
  253. for( var i = 0; i < SessionStorge.length; i++ )
  254. {
  255. var varSessionData = {};
  256. varSessionData["StorageKey"] = SessionStorge.key(i);
  257. varSessionData["StorageValue"] = SessionStorge.getItem(SessionStorge.key(i));
  258. varSessionDataList[i] = varSessionData;
  259. }
  260. jsonValue += ',"SessionStorge":';
  261. jsonValue += JSON.stringify(varSessionDataList);
  262. jsonValue += '';
  263. }
  264. jsonValue += '}';
  265. var ntkobr=ntkoBrowser.NtkoBrower();
  266. if(ntkobr){
  267. window.postMessage({ type: "FROM_NTKO_PAGE", text: jsonValue }, "*");
  268. }else{
  269. ntkowin=b64_md5(strURL);
  270. var ntkowidth=window.screen.width;
  271. var ntkoheight=window.screen.height;
  272. if(ntkoList.length>=12){
  273. alert("不支持更多的窗口");
  274. }else{
  275. for(var i=0;i<ntkoWinOpen.length;i++){
  276. if(ntkoList.length==0){
  277. ntkoJsonIe='{"name":"'+ntkowin+'","ntkosize":"'+i+'","ntkowindow":"'+ntkoWinOpen[i]+'"}';
  278. ntkoList.push(ntkoJsonIe);
  279. ntkoWinOpen[i]=window.open(strURL,ntkowin,"height="+ntkoheight+", width="+ntkowidth+", top=0,left=0,titlebar=no,toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
  280. ntkoWinOpen[i].resizeTo(screen.availWidth,screen.availHeight);
  281. ntkoWinOpen[i].focus();
  282. return;
  283. }else{
  284. for(var j=0;j<ntkoList.length;j++){
  285. var ntkoiename=JSON.parse(ntkoList[j]);
  286. if(ntkoiename.name==ntkowin){
  287. var ntkoi=ntkoiename.ntkosize;
  288. try{
  289. ntkoWinOpen[ntkoi].location.href;
  290. }catch(e){
  291. ntkoWinOpen[ntkoi]=window.open(strURL,ntkowin,"height="+ntkoheight+", width="+ntkowidth+", top=0,left=0,titlebar=no,toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
  292. ntkoWinOpen[ntkoi].resizeTo(screen.availWidth,screen.availHeight);
  293. ntkoWinOpen[ntkoi].focus();
  294. return;
  295. }
  296. ntkoWinOpen[ntkoi].focus();
  297. return;
  298. }
  299. }
  300. try{
  301. if(ntkoWinOpen[i].indexOf("ntkoWinOpen")!=-1){
  302. ntkoJsonIe='{"name":"'+ntkowin+'","ntkosize":"'+i+'","ntkowindow":"'+ntkoWinOpen[i]+'"}';
  303. ntkoList.push(ntkoJsonIe);
  304. ntkoWinOpen[i]=window.open(strURL,ntkowin,"height="+ntkoheight+", width="+ntkowidth+", top=0,left=0,titlebar=no,toolbar =no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
  305. ntkoWinOpen[i].resizeTo(screen.availWidth,screen.availHeight);
  306. ntkoWinOpen[i].focus();
  307. return;
  308. }
  309. }catch(e){
  310. }
  311. }
  312. }
  313. }
  314. }
  315. },
  316. NtkoWShell:function(){
  317. },
  318. NtkoiTop:function(){
  319. return (window.screen.height-30-300)/2;
  320. },
  321. NtkoiLeft:function(){
  322. return (window.screen.width-10-400)/2;
  323. },
  324. NtkoBrower:function(){
  325. if(browser=="IE"){
  326. return false;
  327. }
  328. if(browser=="firefox"){
  329. if(userAgent.indexOf("Windows NT 5.1") > -1){
  330. return false;
  331. }
  332. if(version>="50"){
  333. return true;
  334. }else{
  335. return false;
  336. }
  337. }
  338. if(browser=="chrome"){
  339. if(userAgent.indexOf("Windows NT 5.1") > -1){
  340. return false;
  341. }
  342. if(version>="45"){
  343. return true;
  344. }else{
  345. return false;
  346. }
  347. }
  348. if(browser=="edg"){
  349. return true;
  350. }
  351. },
  352. NtkoStrURL:function(strURL)
  353. {
  354. var testurl =window.location.search;
  355. var docUrl=document.location.toString();
  356. var wpathname= window.document.location.pathname;
  357. var pos=docUrl.indexOf(wpathname);
  358. var relUrl= docUrl.substring(0,pos);
  359. if( ( null === strURL ) || ( "" === strURL ) )
  360. {
  361. alert(" The Param strURL of openWindow() is NULL or empty. ");
  362. return;
  363. }
  364. var strLowser = strURL.toLowerCase();
  365. if( '/' != strURL.charAt(0) )
  366. {
  367. if( ( "http://" === strLowser.substr(0,7) ) || ( "https://" === strLowser.substr(0,8) ) )
  368. {}
  369. else
  370. {
  371. if(strURL.indexOf("../")==-1)
  372. {
  373. var pathName = window.location.href;
  374. var varLength = pathName.lastIndexOf("/");
  375. strURL = pathName.substr( 0, varLength + 1 ) + strURL;
  376. }
  377. else
  378. {
  379. var strURLlen=strURL.length;
  380. strURL=strURL.substring(2,strURLlen);
  381. strURL = relUrl +strURL;
  382. }
  383. if(strURL.indexOf(testurl)==-1)
  384. {
  385. if(strURL.indexOf("?")==-1)
  386. {
  387. strURL=strURL+testurl
  388. }
  389. else
  390. {
  391. var docof= strURL.indexOf("?");
  392. var docend=strURL.length;
  393. var docs=strURL.substring(0,docof);
  394. var docsurl=strURL.substring(docof+1,docend);
  395. strURL=docs+testurl+"&"+docsurl;
  396. }
  397. }
  398. }
  399. }
  400. else
  401. {
  402. var strURLlen=strURL.length;
  403. strURL=strURL.substring(0,strURLlen);
  404. strURL = relUrl+ strURL;
  405. }
  406. return strURL;
  407. }
  408. };
  409. if(browser!="IE")
  410. {
  411. window.addEventListener("message", function(event)
  412. {
  413. if ( event.source != window )
  414. return;
  415. if (event.data.type && (event.data.type == "FROM_NTKO_CONTEXT_PAGE"))
  416. {
  417. var vJsonData = JSON.parse( event.data.text );
  418. var jsonData = vJsonData["ntkoData"];
  419. if( typeof jsonData !== "undefined" )
  420. {
  421. if( varNtkoGUID === jsonData["ntkoGUID"] )
  422. {
  423. if( "ntkoClose" === jsonData["functionName"] )
  424. {
  425. // 调用关闭事件
  426. try
  427. {
  428. eval('ntkoCloseEvent()');
  429. }
  430. catch(e)
  431. {}
  432. }
  433. else if( "ntkoReturnValueToParentPage" === jsonData["functionName"] )
  434. {
  435. // 调用返回值事件,解析值
  436. var varFunctionName = jsonData["parentExecutionFunction"]; // 要执行的函数名
  437. if( typeof varFunctionName != 'undefined' && ( ( null != varFunctionName ) && ( "" != varFunctionName ) ) )
  438. {
  439. var varFunctionAgrvs = jsonData["FunctionArgs"]; // 传递过来的参数值
  440. if( typeof varFunctionAgrvs != 'undefined' && ( ( null != varFunctionAgrvs ) && ( "" != varFunctionAgrvs ) ) )
  441. {
  442. // 调用eval执行函数
  443. eval( varFunctionName + "( varFunctionAgrvs[0], varFunctionAgrvs[1], varFunctionAgrvs[2], varFunctionAgrvs[3]," +
  444. "varFunctionAgrvs[4],varFunctionAgrvs[5],varFunctionAgrvs[6],varFunctionAgrvs[7],varFunctionAgrvs[8]);" );
  445. }
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }, false);
  452. }
  453. if(browser=="IE")
  454. {
  455. if(version<=8)
  456. {
  457. }
  458. else
  459. {
  460. window.addEventListener("message",function(event)
  461. {
  462. if(event.data.type=="ntkowordie")
  463. {
  464. var str=event.data.text;
  465. var Jsondata=JSON.parse(str);
  466. var jsonData = Jsondata["ntkodata"];
  467. var varFunctionAgrvsArray=Jsondata["ntkotext"];
  468. var varFunctionAgrvs= varFunctionAgrvsArray.split(",");
  469. if( typeof jsonData !== "undefined" )
  470. {
  471. if( typeof varFunctionAgrvs != 'undefined' && ( ( null != varFunctionAgrvs ) && ( "" != varFunctionAgrvs ) ) )
  472. {
  473. eval( jsonData + "( varFunctionAgrvs[0], varFunctionAgrvs[1], varFunctionAgrvs[2], varFunctionAgrvs[3]," +
  474. "varFunctionAgrvs[4],varFunctionAgrvs[5],varFunctionAgrvs[6],varFunctionAgrvs[7],varFunctionAgrvs[8]);" );
  475. }
  476. }
  477. }
  478. },false);
  479. }
  480. }
  481. function ieattachEventntko(data,varFunctionAgrvs)
  482. {
  483. if( typeof data !== "undefined" )
  484. {
  485. if( typeof varFunctionAgrvs != 'undefined' && ( ( null != varFunctionAgrvs ) && ( "" != varFunctionAgrvs ) ) )
  486. {
  487. eval( data + "( varFunctionAgrvs[0], varFunctionAgrvs[1], varFunctionAgrvs[2], varFunctionAgrvs[3]," +
  488. "varFunctionAgrvs[4],varFunctionAgrvs[5],varFunctionAgrvs[6],varFunctionAgrvs[7],varFunctionAgrvs[8]);" );
  489. }
  490. }
  491. }
  492. function ntkoSendDataToChildtext(ntkoDataSendUrl)
  493. {
  494. if(ntkoSendDataToChildSData!=null&&ntkoSendDataToChildSData!="")
  495. {
  496. ntkoBrowser.ntkoSendDataToChild(ntkoDataSendUrl,ntkoSendDataToChildSData);
  497. }
  498. }
  499. /*___md5___*/
  500. var hexcase = 0;
  501. var b64pad = "";
  502. var chrsz = 8;
  503. function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
  504. function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
  505. function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
  506. function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
  507. function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
  508. function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
  509. function md5_vm_test()
  510. {
  511. return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
  512. }
  513. function core_md5(x, len)
  514. {
  515. x[len >> 5] |= 0x80 << ((len) % 32);
  516. x[(((len + 64) >>> 9) << 4) + 14] = len;
  517. var a = 1732584193;
  518. var b = -271733879;
  519. var c = -1732584194;
  520. var d = 271733878;
  521. for(var i = 0; i < x.length; i += 16)
  522. {
  523. var olda = a;
  524. var oldb = b;
  525. var oldc = c;
  526. var oldd = d;
  527. a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  528. d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  529. c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
  530. b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  531. a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  532. d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
  533. c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  534. b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  535. a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
  536. d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  537. c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  538. b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  539. a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
  540. d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  541. c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  542. b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
  543. a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  544. d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  545. c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
  546. b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  547. a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  548. d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
  549. c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  550. b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  551. a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
  552. d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  553. c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  554. b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
  555. a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  556. d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  557. c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
  558. b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  559. a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  560. d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  561. c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
  562. b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  563. a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  564. d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
  565. c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  566. b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  567. a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
  568. d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  569. c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  570. b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
  571. a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  572. d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  573. c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
  574. b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  575. a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  576. d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
  577. c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  578. b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  579. a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
  580. d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  581. c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  582. b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  583. a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
  584. d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  585. c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  586. b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
  587. a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  588. d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  589. c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
  590. b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  591. a = safe_add(a, olda);
  592. b = safe_add(b, oldb);
  593. c = safe_add(c, oldc);
  594. d = safe_add(d, oldd);
  595. }
  596. return Array(a, b, c, d);
  597. }
  598. function md5_cmn(q, a, b, x, s, t)
  599. {
  600. return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  601. }
  602. function md5_ff(a, b, c, d, x, s, t)
  603. {
  604. return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
  605. }
  606. function md5_gg(a, b, c, d, x, s, t)
  607. {
  608. return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
  609. }
  610. function md5_hh(a, b, c, d, x, s, t)
  611. {
  612. return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  613. }
  614. function md5_ii(a, b, c, d, x, s, t)
  615. {
  616. return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
  617. }
  618. function core_hmac_md5(key, data)
  619. {
  620. var bkey = str2binl(key);
  621. if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
  622. var ipad = Array(16), opad = Array(16);
  623. for(var i = 0; i < 16; i++)
  624. {
  625. ipad[i] = bkey[i] ^ 0x36363636;
  626. opad[i] = bkey[i] ^ 0x5C5C5C5C;
  627. }
  628. var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  629. return core_md5(opad.concat(hash), 512 + 128);
  630. }
  631. function safe_add(x, y)
  632. {
  633. var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  634. var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  635. return (msw << 16) | (lsw & 0xFFFF);
  636. }
  637. function bit_rol(num, cnt)
  638. {
  639. return (num << cnt) | (num >>> (32 - cnt));
  640. }
  641. function str2binl(str)
  642. {
  643. var bin = Array();
  644. var mask = (1 << chrsz) - 1;
  645. for(var i = 0; i < str.length * chrsz; i += chrsz)
  646. bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  647. return bin;
  648. }
  649. function binl2str(bin)
  650. {
  651. var str = "";
  652. var mask = (1 << chrsz) - 1;
  653. for(var i = 0; i < bin.length * 32; i += chrsz)
  654. str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  655. return str;
  656. }
  657. function binl2hex(binarray)
  658. {
  659. var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  660. var str = "";
  661. for(var i = 0; i < binarray.length * 4; i++)
  662. {
  663. str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
  664. hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
  665. }
  666. return str;
  667. }
  668. function binl2b64(binarray)
  669. {
  670. var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  671. var str = "";
  672. for(var i = 0; i < binarray.length * 4; i += 3)
  673. {
  674. var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
  675. | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
  676. | ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
  677. for(var j = 0; j < 4; j++)
  678. {
  679. if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
  680. else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
  681. }
  682. }
  683. return str;
  684. }