最近新的系统开发用的是Cookie存储用户信息,使用des加密

工具类如下所示:

  1. /**
  2. * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
  3. */
  4. package com.lms.common.utils;
  5.  
  6. import java.io.UnsupportedEncodingException;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9.  
  10. /**
  11. * DES加密解密工具
  12. * 加密:DesUtils.encode("admin","1,2,3");
  13. * 解密:DesUtils.decode("012C2C9BA925FAF8045B2FD9B02A2664","1,2,3");
  14. * @author ThinkGem
  15. */
  16. public class DesUtils {
  17.  
  18. private static DesCore desCore = new DesCore();
  19.  
  20. /**
  21. * DES加密(secretKey代表3个key,用逗号分隔)
  22. */
  23. public static String encode(String data, String secretKey) {
  24. if (StringUtils.isBlank(data)){
  25. return "";
  26. }
  27. String[] ks = StringUtils.split(secretKey, ",");
  28. if (ks.length >= 3){
  29. return desCore.strEnc(data, ks[0], ks[1], ks[2]);
  30. }
  31. return desCore.strEnc(data, secretKey, "", "");
  32. }
  33.  
  34. /**
  35. * DES解密(secretKey代表3个key,用逗号分隔)
  36. */
  37. public static String decode(String data, String secretKey) {
  38. if (StringUtils.isBlank(data)){
  39. return "";
  40. }
  41. String[] ks = StringUtils.split(secretKey, ",");
  42. if (ks.length >= 3){
  43. return desCore.strDec(data, ks[0], ks[1], ks[2]);
  44. }
  45. return desCore.strDec(data, secretKey, "", "");
  46. }
  47.  
  48. /**
  49. * DES加密/解密
  50. * @Copyright Copyright (c) 2006
  51. * @author Guapo
  52. */
  53. @SuppressWarnings({"rawtypes","unused","unchecked"})
  54. static class DesCore {
  55.  
  56. /*
  57. * encrypt the string to string made up of hex return the encrypted string
  58. */
  59. public String strEnc(String data, String firstKey, String secondKey, String thirdKey) {
  60.  
  61. int leng = data.length();
  62. String encData = "";
  63. List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;
  64. int firstLength = 0, secondLength = 0, thirdLength = 0;
  65. if (firstKey != null && firstKey != "") {
  66. firstKeyBt = getKeyBytes(firstKey);
  67. firstLength = firstKeyBt.size();
  68. }
  69. if (secondKey != null && secondKey != "") {
  70. secondKeyBt = getKeyBytes(secondKey);
  71. secondLength = secondKeyBt.size();
  72. }
  73. if (thirdKey != null && thirdKey != "") {
  74. thirdKeyBt = getKeyBytes(thirdKey);
  75. thirdLength = thirdKeyBt.size();
  76. }
  77.  
  78. if (leng > 0) {
  79. if (leng < 4) {
  80. int[] bt = strToBt(data);
  81. int[] encByte = null;
  82. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
  83. int[] tempBt;
  84. int x, y, z;
  85. tempBt = bt;
  86. for (x = 0; x < firstLength; x++) {
  87. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  88. }
  89. for (y = 0; y < secondLength; y++) {
  90. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  91. }
  92. for (z = 0; z < thirdLength; z++) {
  93. tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
  94. }
  95. encByte = tempBt;
  96. } else {
  97. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
  98. int[] tempBt;
  99. int x, y;
  100. tempBt = bt;
  101. for (x = 0; x < firstLength; x++) {
  102. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  103. }
  104. for (y = 0; y < secondLength; y++) {
  105. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  106. }
  107. encByte = tempBt;
  108. } else {
  109. if (firstKey != null && firstKey != "") {
  110. int[] tempBt;
  111. int x = 0;
  112. tempBt = bt;
  113. for (x = 0; x < firstLength; x++) {
  114. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  115. }
  116. encByte = tempBt;
  117. }
  118. }
  119. }
  120. encData = bt64ToHex(encByte);
  121. } else {
  122. int iterator = (leng / 4);
  123. int remainder = leng % 4;
  124. int i = 0;
  125. for (i = 0; i < iterator; i++) {
  126. String tempData = data.substring(i * 4 + 0, i * 4 + 4);
  127. int[] tempByte = strToBt(tempData);
  128. int[] encByte = null;
  129. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
  130. int[] tempBt;
  131. int x, y, z;
  132. tempBt = tempByte;
  133. for (x = 0; x < firstLength; x++) {
  134. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  135. }
  136. for (y = 0; y < secondLength; y++) {
  137. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  138. }
  139. for (z = 0; z < thirdLength; z++) {
  140. tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
  141. }
  142. encByte = tempBt;
  143. } else {
  144. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
  145. int[] tempBt;
  146. int x, y;
  147. tempBt = tempByte;
  148. for (x = 0; x < firstLength; x++) {
  149. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  150. }
  151. for (y = 0; y < secondLength; y++) {
  152. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  153. }
  154. encByte = tempBt;
  155. } else {
  156. if (firstKey != null && firstKey != "") {
  157. int[] tempBt;
  158. int x;
  159. tempBt = tempByte;
  160. for (x = 0; x < firstLength; x++) {
  161. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  162. }
  163. encByte = tempBt;
  164. }
  165. }
  166. }
  167. encData += bt64ToHex(encByte);
  168. }
  169. if (remainder > 0) {
  170. String remainderData = data.substring(iterator * 4 + 0, leng);
  171. int[] tempByte = strToBt(remainderData);
  172. int[] encByte = null;
  173. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
  174. int[] tempBt;
  175. int x, y, z;
  176. tempBt = tempByte;
  177. for (x = 0; x < firstLength; x++) {
  178. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  179. }
  180. for (y = 0; y < secondLength; y++) {
  181. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  182. }
  183. for (z = 0; z < thirdLength; z++) {
  184. tempBt = enc(tempBt, (int[]) thirdKeyBt.get(z));
  185. }
  186. encByte = tempBt;
  187. } else {
  188. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
  189. int[] tempBt;
  190. int x, y;
  191. tempBt = tempByte;
  192. for (x = 0; x < firstLength; x++) {
  193. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  194. }
  195. for (y = 0; y < secondLength; y++) {
  196. tempBt = enc(tempBt, (int[]) secondKeyBt.get(y));
  197. }
  198. encByte = tempBt;
  199. } else {
  200. if (firstKey != null && firstKey != "") {
  201. int[] tempBt;
  202. int x;
  203. tempBt = tempByte;
  204. for (x = 0; x < firstLength; x++) {
  205. tempBt = enc(tempBt, (int[]) firstKeyBt.get(x));
  206. }
  207. encByte = tempBt;
  208. }
  209. }
  210. }
  211. encData += bt64ToHex(encByte);
  212. }
  213. }
  214. }
  215. return encData;
  216. }
  217.  
  218. /*
  219. * decrypt the encrypted string to the original string
  220. *
  221. * return the original string
  222. */
  223. public String strDec(String data, String firstKey, String secondKey, String thirdKey) {
  224. int leng = data.length();
  225. String decStr = "";
  226. List firstKeyBt = null, secondKeyBt = null, thirdKeyBt = null;
  227. int firstLength = 0, secondLength = 0, thirdLength = 0;
  228. if (firstKey != null && firstKey != "") {
  229. firstKeyBt = getKeyBytes(firstKey);
  230. firstLength = firstKeyBt.size();
  231. }
  232. if (secondKey != null && secondKey != "") {
  233. secondKeyBt = getKeyBytes(secondKey);
  234. secondLength = secondKeyBt.size();
  235. }
  236. if (thirdKey != null && thirdKey != "") {
  237. thirdKeyBt = getKeyBytes(thirdKey);
  238. thirdLength = thirdKeyBt.size();
  239. }
  240.  
  241. int iterator = leng / 16;
  242. int i = 0;
  243. for (i = 0; i < iterator; i++) {
  244. String tempData = data.substring(i * 16 + 0, i * 16 + 16);
  245. String strByte = hexToBt64(tempData);
  246. int[] intByte = new int[64];
  247. int j = 0;
  248. for (j = 0; j < 64; j++) {
  249. intByte[j] = Integer.parseInt(strByte.substring(j, j + 1));
  250. }
  251. int[] decByte = null;
  252. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "" && thirdKey != null && thirdKey != "") {
  253. int[] tempBt;
  254. int x, y, z;
  255. tempBt = intByte;
  256. for (x = thirdLength - 1; x >= 0; x--) {
  257. tempBt = dec(tempBt, (int[]) thirdKeyBt.get(x));
  258. }
  259. for (y = secondLength - 1; y >= 0; y--) {
  260. tempBt = dec(tempBt, (int[]) secondKeyBt.get(y));
  261. }
  262. for (z = firstLength - 1; z >= 0; z--) {
  263. tempBt = dec(tempBt, (int[]) firstKeyBt.get(z));
  264. }
  265. decByte = tempBt;
  266. } else {
  267. if (firstKey != null && firstKey != "" && secondKey != null && secondKey != "") {
  268. int[] tempBt;
  269. int x, y, z;
  270. tempBt = intByte;
  271. for (x = secondLength - 1; x >= 0; x--) {
  272. tempBt = dec(tempBt, (int[]) secondKeyBt.get(x));
  273. }
  274. for (y = firstLength - 1; y >= 0; y--) {
  275. tempBt = dec(tempBt, (int[]) firstKeyBt.get(y));
  276. }
  277. decByte = tempBt;
  278. } else {
  279. if (firstKey != null && firstKey != "") {
  280. int[] tempBt;
  281. int x, y, z;
  282. tempBt = intByte;
  283. for (x = firstLength - 1; x >= 0; x--) {
  284. tempBt = dec(tempBt, (int[]) firstKeyBt.get(x));
  285. }
  286. decByte = tempBt;
  287. }
  288. }
  289. }
  290. decStr += byteToString(decByte);
  291. }
  292. return decStr;
  293. }
  294.  
  295. /*
  296. * chang the string into the bit array
  297. *
  298. * return bit array(it's length % 64 = 0)
  299. */
  300. public List getKeyBytes(String key) {
  301. List keyBytes = new ArrayList();
  302. int leng = key.length();
  303. int iterator = (leng / 4);
  304. int remainder = leng % 4;
  305. int i = 0;
  306. for (i = 0; i < iterator; i++) {
  307. keyBytes.add(i, strToBt(key.substring(i * 4 + 0, i * 4 + 4)));
  308. }
  309. if (remainder > 0) {
  310. // keyBytes[i] = strToBt(key.substring(i*4+0,leng));
  311. keyBytes.add(i, strToBt(key.substring(i * 4 + 0, leng)));
  312. }
  313. return keyBytes;
  314. }
  315.  
  316. /*
  317. * chang the string(it's length <= 4) into the bit array
  318. *
  319. * return bit array(it's length = 64)
  320. */
  321. public int[] strToBt(String str) {
  322. int leng = str.length();
  323. int[] bt = new int[64];
  324. if (leng < 4) {
  325. int i = 0, j = 0, p = 0, q = 0;
  326. for (i = 0; i < leng; i++) {
  327. int k = str.charAt(i);
  328. for (j = 0; j < 16; j++) {
  329. int pow = 1, m = 0;
  330. for (m = 15; m > j; m--) {
  331. pow *= 2;
  332. }
  333. // bt.set(16*i+j,""+(k/pow)%2));
  334. bt[16 * i + j] = (k / pow) % 2;
  335. }
  336. }
  337. for (p = leng; p < 4; p++) {
  338. int k = 0;
  339. for (q = 0; q < 16; q++) {
  340. int pow = 1, m = 0;
  341. for (m = 15; m > q; m--) {
  342. pow *= 2;
  343. }
  344. // bt[16*p+q]=parseInt(k/pow)%2;
  345. // bt.add(16*p+q,""+((k/pow)%2));
  346. bt[16 * p + q] = (k / pow) % 2;
  347. }
  348. }
  349. } else {
  350. for (int i = 0; i < 4; i++) {
  351. int k = str.charAt(i);
  352. for (int j = 0; j < 16; j++) {
  353. int pow = 1;
  354. for (int m = 15; m > j; m--) {
  355. pow *= 2;
  356. }
  357. // bt[16*i+j]=parseInt(k/pow)%2;
  358. // bt.add(16*i+j,""+((k/pow)%2));
  359. bt[16 * i + j] = (k / pow) % 2;
  360. }
  361. }
  362. }
  363. return bt;
  364. }
  365.  
  366. /*
  367. * chang the bit(it's length = 4) into the hex
  368. *
  369. * return hex
  370. */
  371. public String bt4ToHex(String binary) {
  372. String hex = "";
  373. if (binary.equalsIgnoreCase("0000")) {
  374. hex = "0";
  375. } else if (binary.equalsIgnoreCase("0001")) {
  376. hex = "1";
  377. } else if (binary.equalsIgnoreCase("0010")) {
  378. hex = "2";
  379. } else if (binary.equalsIgnoreCase("0011")) {
  380. hex = "3";
  381. } else if (binary.equalsIgnoreCase("0100")) {
  382. hex = "4";
  383. } else if (binary.equalsIgnoreCase("0101")) {
  384. hex = "5";
  385. } else if (binary.equalsIgnoreCase("0110")) {
  386. hex = "6";
  387. } else if (binary.equalsIgnoreCase("0111")) {
  388. hex = "7";
  389. } else if (binary.equalsIgnoreCase("1000")) {
  390. hex = "8";
  391. } else if (binary.equalsIgnoreCase("1001")) {
  392. hex = "9";
  393. } else if (binary.equalsIgnoreCase("1010")) {
  394. hex = "A";
  395. } else if (binary.equalsIgnoreCase("1011")) {
  396. hex = "B";
  397. } else if (binary.equalsIgnoreCase("1100")) {
  398. hex = "C";
  399. } else if (binary.equalsIgnoreCase("1101")) {
  400. hex = "D";
  401. } else if (binary.equalsIgnoreCase("1110")) {
  402. hex = "E";
  403. } else if (binary.equalsIgnoreCase("1111")) {
  404. hex = "F";
  405. }
  406.  
  407. return hex;
  408. }
  409.  
  410. /*
  411. * chang the hex into the bit(it's length = 4)
  412. *
  413. * return the bit(it's length = 4)
  414. */
  415. public String hexToBt4(String hex) {
  416. String binary = "";
  417. if (hex.equalsIgnoreCase("0")) {
  418. binary = "0000";
  419. } else if (hex.equalsIgnoreCase("1")) {
  420. binary = "0001";
  421. }
  422. if (hex.equalsIgnoreCase("2")) {
  423. binary = "0010";
  424. }
  425. if (hex.equalsIgnoreCase("3")) {
  426. binary = "0011";
  427. }
  428. if (hex.equalsIgnoreCase("4")) {
  429. binary = "0100";
  430. }
  431. if (hex.equalsIgnoreCase("5")) {
  432. binary = "0101";
  433. }
  434. if (hex.equalsIgnoreCase("6")) {
  435. binary = "0110";
  436. }
  437. if (hex.equalsIgnoreCase("7")) {
  438. binary = "0111";
  439. }
  440. if (hex.equalsIgnoreCase("8")) {
  441. binary = "1000";
  442. }
  443. if (hex.equalsIgnoreCase("9")) {
  444. binary = "1001";
  445. }
  446. if (hex.equalsIgnoreCase("A")) {
  447. binary = "1010";
  448. }
  449. if (hex.equalsIgnoreCase("B")) {
  450. binary = "1011";
  451. }
  452. if (hex.equalsIgnoreCase("C")) {
  453. binary = "1100";
  454. }
  455. if (hex.equalsIgnoreCase("D")) {
  456. binary = "1101";
  457. }
  458. if (hex.equalsIgnoreCase("E")) {
  459. binary = "1110";
  460. }
  461. if (hex.equalsIgnoreCase("F")) {
  462. binary = "1111";
  463. }
  464. return binary;
  465. }
  466.  
  467. /*
  468. * chang the bit(it's length = 64) into the string
  469. *
  470. * return string
  471. */
  472. public String byteToString(int[] byteData) {
  473. String str = "";
  474. for (int i = 0; i < 4; i++) {
  475. int count = 0;
  476. for (int j = 0; j < 16; j++) {
  477. int pow = 1;
  478. for (int m = 15; m > j; m--) {
  479. pow *= 2;
  480. }
  481. count += byteData[16 * i + j] * pow;
  482. }
  483. if (count != 0) {
  484. str += "" + (char) (count);
  485. }
  486. }
  487. return str;
  488. }
  489.  
  490. public String bt64ToHex(int[] byteData) {
  491. String hex = "";
  492. for (int i = 0; i < 16; i++) {
  493. String bt = "";
  494. for (int j = 0; j < 4; j++) {
  495. bt += byteData[i * 4 + j];
  496. }
  497. hex += bt4ToHex(bt);
  498. }
  499. return hex;
  500. }
  501.  
  502. public String hexToBt64(String hex) {
  503. String binary = "";
  504. for (int i = 0; i < 16; i++) {
  505. binary += hexToBt4(hex.substring(i, i + 1));
  506. }
  507. return binary;
  508. }
  509.  
  510. /*
  511. * the 64 bit des core arithmetic
  512. */
  513.  
  514. public int[] enc(int[] dataByte, int[] keyByte) {
  515. int[][] keys = generateKeys(keyByte);
  516. int[] ipByte = initPermute(dataByte);
  517. int[] ipLeft = new int[32];
  518. int[] ipRight = new int[32];
  519. int[] tempLeft = new int[32];
  520. int i = 0, j = 0, k = 0, m = 0, n = 0;
  521. for (k = 0; k < 32; k++) {
  522. ipLeft[k] = ipByte[k];
  523. ipRight[k] = ipByte[32 + k];
  524. }
  525. for (i = 0; i < 16; i++) {
  526. for (j = 0; j < 32; j++) {
  527. tempLeft[j] = ipLeft[j];
  528. ipLeft[j] = ipRight[j];
  529. }
  530. int[] key = new int[48];
  531. for (m = 0; m < 48; m++) {
  532. key[m] = keys[i][m];
  533. }
  534. int[] tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
  535. for (n = 0; n < 32; n++) {
  536. ipRight[n] = tempRight[n];
  537. }
  538.  
  539. }
  540.  
  541. int[] finalData = new int[64];
  542. for (i = 0; i < 32; i++) {
  543. finalData[i] = ipRight[i];
  544. finalData[32 + i] = ipLeft[i];
  545. }
  546. return finallyPermute(finalData);
  547. }
  548.  
  549. public int[] dec(int[] dataByte, int[] keyByte) {
  550. int[][] keys = generateKeys(keyByte);
  551. int[] ipByte = initPermute(dataByte);
  552. int[] ipLeft = new int[32];
  553. int[] ipRight = new int[32];
  554. int[] tempLeft = new int[32];
  555. int i = 0, j = 0, k = 0, m = 0, n = 0;
  556. for (k = 0; k < 32; k++) {
  557. ipLeft[k] = ipByte[k];
  558. ipRight[k] = ipByte[32 + k];
  559. }
  560. for (i = 15; i >= 0; i--) {
  561. for (j = 0; j < 32; j++) {
  562. tempLeft[j] = ipLeft[j];
  563. ipLeft[j] = ipRight[j];
  564. }
  565. int[] key = new int[48];
  566. for (m = 0; m < 48; m++) {
  567. key[m] = keys[i][m];
  568. }
  569.  
  570. int[] tempRight = xor(pPermute(sBoxPermute(xor(expandPermute(ipRight), key))), tempLeft);
  571. for (n = 0; n < 32; n++) {
  572. ipRight[n] = tempRight[n];
  573. }
  574. }
  575.  
  576. int[] finalData = new int[64];
  577. for (i = 0; i < 32; i++) {
  578. finalData[i] = ipRight[i];
  579. finalData[32 + i] = ipLeft[i];
  580. }
  581. return finallyPermute(finalData);
  582. }
  583.  
  584. public int[] initPermute(int[] originalData) {
  585. int[] ipByte = new int[64];
  586. int i = 0, m = 1, n = 0, j, k;
  587. for (i = 0, m = 1, n = 0; i < 4; i++, m += 2, n += 2) {
  588. for (j = 7, k = 0; j >= 0; j--, k++) {
  589. ipByte[i * 8 + k] = originalData[j * 8 + m];
  590. ipByte[i * 8 + k + 32] = originalData[j * 8 + n];
  591. }
  592. }
  593. return ipByte;
  594. }
  595.  
  596. public int[] expandPermute(int[] rightData) {
  597. int[] epByte = new int[48];
  598. int i, j;
  599. for (i = 0; i < 8; i++) {
  600. if (i == 0) {
  601. epByte[i * 6 + 0] = rightData[31];
  602. } else {
  603. epByte[i * 6 + 0] = rightData[i * 4 - 1];
  604. }
  605. epByte[i * 6 + 1] = rightData[i * 4 + 0];
  606. epByte[i * 6 + 2] = rightData[i * 4 + 1];
  607. epByte[i * 6 + 3] = rightData[i * 4 + 2];
  608. epByte[i * 6 + 4] = rightData[i * 4 + 3];
  609. if (i == 7) {
  610. epByte[i * 6 + 5] = rightData[0];
  611. } else {
  612. epByte[i * 6 + 5] = rightData[i * 4 + 4];
  613. }
  614. }
  615. return epByte;
  616. }
  617.  
  618. public int[] xor(int[] byteOne, int[] byteTwo) {
  619. // var xorByte = new Array(byteOne.length);
  620. // for(int i = 0;i < byteOne.length; i ++){
  621. // xorByte[i] = byteOne[i] ^ byteTwo[i];
  622. // }
  623. // return xorByte;
  624. int[] xorByte = new int[byteOne.length];
  625. for (int i = 0; i < byteOne.length; i++) {
  626. xorByte[i] = byteOne[i] ^ byteTwo[i];
  627. }
  628. return xorByte;
  629. }
  630.  
  631. public int[] sBoxPermute(int[] expandByte) {
  632.  
  633. // var sBoxByte = new Array(32);
  634. int[] sBoxByte = new int[32];
  635. String binary = "";
  636. int[][] s1 = { { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 }, { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 },
  637. { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 }, { 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 } };
  638.  
  639. /* Table - s2 */
  640. int[][] s2 = { { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 }, { 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 },
  641. { 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 }, { 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 } };
  642.  
  643. /* Table - s3 */
  644. int[][] s3 = { { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 }, { 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 },
  645. { 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 }, { 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 } };
  646. /* Table - s4 */
  647. int[][] s4 = { { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 }, { 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 },
  648. { 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 }, { 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 } };
  649.  
  650. /* Table - s5 */
  651. int[][] s5 = { { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 }, { 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 },
  652. { 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 }, { 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 } };
  653.  
  654. /* Table - s6 */
  655. int[][] s6 = { { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 }, { 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 },
  656. { 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 }, { 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 } };
  657.  
  658. /* Table - s7 */
  659. int[][] s7 = { { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 }, { 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 },
  660. { 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 }, { 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 } };
  661.  
  662. /* Table - s8 */
  663. int[][] s8 = { { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 }, { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 },
  664. { 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 }, { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 } };
  665.  
  666. for (int m = 0; m < 8; m++) {
  667. int i = 0, j = 0;
  668. i = expandByte[m * 6 + 0] * 2 + expandByte[m * 6 + 5];
  669. j = expandByte[m * 6 + 1] * 2 * 2 * 2 + expandByte[m * 6 + 2] * 2 * 2 + expandByte[m * 6 + 3] * 2 + expandByte[m * 6 + 4];
  670. switch (m) {
  671. case 0:
  672. binary = getBoxBinary(s1[i][j]);
  673. break;
  674. case 1:
  675. binary = getBoxBinary(s2[i][j]);
  676. break;
  677. case 2:
  678. binary = getBoxBinary(s3[i][j]);
  679. break;
  680. case 3:
  681. binary = getBoxBinary(s4[i][j]);
  682. break;
  683. case 4:
  684. binary = getBoxBinary(s5[i][j]);
  685. break;
  686. case 5:
  687. binary = getBoxBinary(s6[i][j]);
  688. break;
  689. case 6:
  690. binary = getBoxBinary(s7[i][j]);
  691. break;
  692. case 7:
  693. binary = getBoxBinary(s8[i][j]);
  694. break;
  695. }
  696. sBoxByte[m * 4 + 0] = Integer.parseInt(binary.substring(0, 1));
  697. sBoxByte[m * 4 + 1] = Integer.parseInt(binary.substring(1, 2));
  698. sBoxByte[m * 4 + 2] = Integer.parseInt(binary.substring(2, 3));
  699. sBoxByte[m * 4 + 3] = Integer.parseInt(binary.substring(3, 4));
  700. }
  701. return sBoxByte;
  702. }
  703.  
  704. public int[] pPermute(int[] sBoxByte) {
  705. int[] pBoxPermute = new int[32];
  706. pBoxPermute[0] = sBoxByte[15];
  707. pBoxPermute[1] = sBoxByte[6];
  708. pBoxPermute[2] = sBoxByte[19];
  709. pBoxPermute[3] = sBoxByte[20];
  710. pBoxPermute[4] = sBoxByte[28];
  711. pBoxPermute[5] = sBoxByte[11];
  712. pBoxPermute[6] = sBoxByte[27];
  713. pBoxPermute[7] = sBoxByte[16];
  714. pBoxPermute[8] = sBoxByte[0];
  715. pBoxPermute[9] = sBoxByte[14];
  716. pBoxPermute[10] = sBoxByte[22];
  717. pBoxPermute[11] = sBoxByte[25];
  718. pBoxPermute[12] = sBoxByte[4];
  719. pBoxPermute[13] = sBoxByte[17];
  720. pBoxPermute[14] = sBoxByte[30];
  721. pBoxPermute[15] = sBoxByte[9];
  722. pBoxPermute[16] = sBoxByte[1];
  723. pBoxPermute[17] = sBoxByte[7];
  724. pBoxPermute[18] = sBoxByte[23];
  725. pBoxPermute[19] = sBoxByte[13];
  726. pBoxPermute[20] = sBoxByte[31];
  727. pBoxPermute[21] = sBoxByte[26];
  728. pBoxPermute[22] = sBoxByte[2];
  729. pBoxPermute[23] = sBoxByte[8];
  730. pBoxPermute[24] = sBoxByte[18];
  731. pBoxPermute[25] = sBoxByte[12];
  732. pBoxPermute[26] = sBoxByte[29];
  733. pBoxPermute[27] = sBoxByte[5];
  734. pBoxPermute[28] = sBoxByte[21];
  735. pBoxPermute[29] = sBoxByte[10];
  736. pBoxPermute[30] = sBoxByte[3];
  737. pBoxPermute[31] = sBoxByte[24];
  738. return pBoxPermute;
  739. }
  740.  
  741. public int[] finallyPermute(int[] endByte) {
  742. int[] fpByte = new int[64];
  743. fpByte[0] = endByte[39];
  744. fpByte[1] = endByte[7];
  745. fpByte[2] = endByte[47];
  746. fpByte[3] = endByte[15];
  747. fpByte[4] = endByte[55];
  748. fpByte[5] = endByte[23];
  749. fpByte[6] = endByte[63];
  750. fpByte[7] = endByte[31];
  751. fpByte[8] = endByte[38];
  752. fpByte[9] = endByte[6];
  753. fpByte[10] = endByte[46];
  754. fpByte[11] = endByte[14];
  755. fpByte[12] = endByte[54];
  756. fpByte[13] = endByte[22];
  757. fpByte[14] = endByte[62];
  758. fpByte[15] = endByte[30];
  759. fpByte[16] = endByte[37];
  760. fpByte[17] = endByte[5];
  761. fpByte[18] = endByte[45];
  762. fpByte[19] = endByte[13];
  763. fpByte[20] = endByte[53];
  764. fpByte[21] = endByte[21];
  765. fpByte[22] = endByte[61];
  766. fpByte[23] = endByte[29];
  767. fpByte[24] = endByte[36];
  768. fpByte[25] = endByte[4];
  769. fpByte[26] = endByte[44];
  770. fpByte[27] = endByte[12];
  771. fpByte[28] = endByte[52];
  772. fpByte[29] = endByte[20];
  773. fpByte[30] = endByte[60];
  774. fpByte[31] = endByte[28];
  775. fpByte[32] = endByte[35];
  776. fpByte[33] = endByte[3];
  777. fpByte[34] = endByte[43];
  778. fpByte[35] = endByte[11];
  779. fpByte[36] = endByte[51];
  780. fpByte[37] = endByte[19];
  781. fpByte[38] = endByte[59];
  782. fpByte[39] = endByte[27];
  783. fpByte[40] = endByte[34];
  784. fpByte[41] = endByte[2];
  785. fpByte[42] = endByte[42];
  786. fpByte[43] = endByte[10];
  787. fpByte[44] = endByte[50];
  788. fpByte[45] = endByte[18];
  789. fpByte[46] = endByte[58];
  790. fpByte[47] = endByte[26];
  791. fpByte[48] = endByte[33];
  792. fpByte[49] = endByte[1];
  793. fpByte[50] = endByte[41];
  794. fpByte[51] = endByte[9];
  795. fpByte[52] = endByte[49];
  796. fpByte[53] = endByte[17];
  797. fpByte[54] = endByte[57];
  798. fpByte[55] = endByte[25];
  799. fpByte[56] = endByte[32];
  800. fpByte[57] = endByte[0];
  801. fpByte[58] = endByte[40];
  802. fpByte[59] = endByte[8];
  803. fpByte[60] = endByte[48];
  804. fpByte[61] = endByte[16];
  805. fpByte[62] = endByte[56];
  806. fpByte[63] = endByte[24];
  807. return fpByte;
  808. }
  809.  
  810. public String getBoxBinary(int i) {
  811. String binary = "";
  812. switch (i) {
  813. case 0:
  814. binary = "0000";
  815. break;
  816. case 1:
  817. binary = "0001";
  818. break;
  819. case 2:
  820. binary = "0010";
  821. break;
  822. case 3:
  823. binary = "0011";
  824. break;
  825. case 4:
  826. binary = "0100";
  827. break;
  828. case 5:
  829. binary = "0101";
  830. break;
  831. case 6:
  832. binary = "0110";
  833. break;
  834. case 7:
  835. binary = "0111";
  836. break;
  837. case 8:
  838. binary = "1000";
  839. break;
  840. case 9:
  841. binary = "1001";
  842. break;
  843. case 10:
  844. binary = "1010";
  845. break;
  846. case 11:
  847. binary = "1011";
  848. break;
  849. case 12:
  850. binary = "1100";
  851. break;
  852. case 13:
  853. binary = "1101";
  854. break;
  855. case 14:
  856. binary = "1110";
  857. break;
  858. case 15:
  859. binary = "1111";
  860. break;
  861. }
  862. return binary;
  863. }
  864.  
  865. /*
  866. * generate 16 keys for xor
  867. */
  868. public int[][] generateKeys(int[] keyByte) {
  869. int[] key = new int[56];
  870. int[][] keys = new int[16][48];
  871.  
  872. // keys[ 0] = new Array();
  873. // keys[ 1] = new Array();
  874. // keys[ 2] = new Array();
  875. // keys[ 3] = new Array();
  876. // keys[ 4] = new Array();
  877. // keys[ 5] = new Array();
  878. // keys[ 6] = new Array();
  879. // keys[ 7] = new Array();
  880. // keys[ 8] = new Array();
  881. // keys[ 9] = new Array();
  882. // keys[10] = new Array();
  883. // keys[11] = new Array();
  884. // keys[12] = new Array();
  885. // keys[13] = new Array();
  886. // keys[14] = new Array();
  887. // keys[15] = new Array();
  888. int[] loop = new int[] { 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 };
  889.  
  890. for (int i = 0; i < 7; i++) {
  891. for (int j = 0, k = 7; j < 8; j++, k--) {
  892. key[i * 8 + j] = keyByte[8 * k + i];
  893. }
  894. }
  895.  
  896. int i = 0;
  897. for (i = 0; i < 16; i++) {
  898. int tempLeft = 0;
  899. int tempRight = 0;
  900. for (int j = 0; j < loop[i]; j++) {
  901. tempLeft = key[0];
  902. tempRight = key[28];
  903. for (int k = 0; k < 27; k++) {
  904. key[k] = key[k + 1];
  905. key[28 + k] = key[29 + k];
  906. }
  907. key[27] = tempLeft;
  908. key[55] = tempRight;
  909. }
  910. // var tempKey = new Array(48);
  911. int[] tempKey = new int[48];
  912. tempKey[0] = key[13];
  913. tempKey[1] = key[16];
  914. tempKey[2] = key[10];
  915. tempKey[3] = key[23];
  916. tempKey[4] = key[0];
  917. tempKey[5] = key[4];
  918. tempKey[6] = key[2];
  919. tempKey[7] = key[27];
  920. tempKey[8] = key[14];
  921. tempKey[9] = key[5];
  922. tempKey[10] = key[20];
  923. tempKey[11] = key[9];
  924. tempKey[12] = key[22];
  925. tempKey[13] = key[18];
  926. tempKey[14] = key[11];
  927. tempKey[15] = key[3];
  928. tempKey[16] = key[25];
  929. tempKey[17] = key[7];
  930. tempKey[18] = key[15];
  931. tempKey[19] = key[6];
  932. tempKey[20] = key[26];
  933. tempKey[21] = key[19];
  934. tempKey[22] = key[12];
  935. tempKey[23] = key[1];
  936. tempKey[24] = key[40];
  937. tempKey[25] = key[51];
  938. tempKey[26] = key[30];
  939. tempKey[27] = key[36];
  940. tempKey[28] = key[46];
  941. tempKey[29] = key[54];
  942. tempKey[30] = key[29];
  943. tempKey[31] = key[39];
  944. tempKey[32] = key[50];
  945. tempKey[33] = key[44];
  946. tempKey[34] = key[32];
  947. tempKey[35] = key[47];
  948. tempKey[36] = key[43];
  949. tempKey[37] = key[48];
  950. tempKey[38] = key[38];
  951. tempKey[39] = key[55];
  952. tempKey[40] = key[33];
  953. tempKey[41] = key[52];
  954. tempKey[42] = key[45];
  955. tempKey[43] = key[41];
  956. tempKey[44] = key[49];
  957. tempKey[45] = key[35];
  958. tempKey[46] = key[28];
  959. tempKey[47] = key[31];
  960. int m;
  961. switch (i) {
  962. case 0:
  963. for (m = 0; m < 48; m++) {
  964. keys[0][m] = tempKey[m];
  965. }
  966. break;
  967. case 1:
  968. for (m = 0; m < 48; m++) {
  969. keys[1][m] = tempKey[m];
  970. }
  971. break;
  972. case 2:
  973. for (m = 0; m < 48; m++) {
  974. keys[2][m] = tempKey[m];
  975. }
  976. break;
  977. case 3:
  978. for (m = 0; m < 48; m++) {
  979. keys[3][m] = tempKey[m];
  980. }
  981. break;
  982. case 4:
  983. for (m = 0; m < 48; m++) {
  984. keys[4][m] = tempKey[m];
  985. }
  986. break;
  987. case 5:
  988. for (m = 0; m < 48; m++) {
  989. keys[5][m] = tempKey[m];
  990. }
  991. break;
  992. case 6:
  993. for (m = 0; m < 48; m++) {
  994. keys[6][m] = tempKey[m];
  995. }
  996. break;
  997. case 7:
  998. for (m = 0; m < 48; m++) {
  999. keys[7][m] = tempKey[m];
  1000. }
  1001. break;
  1002. case 8:
  1003. for (m = 0; m < 48; m++) {
  1004. keys[8][m] = tempKey[m];
  1005. }
  1006. break;
  1007. case 9:
  1008. for (m = 0; m < 48; m++) {
  1009. keys[9][m] = tempKey[m];
  1010. }
  1011. break;
  1012. case 10:
  1013. for (m = 0; m < 48; m++) {
  1014. keys[10][m] = tempKey[m];
  1015. }
  1016. break;
  1017. case 11:
  1018. for (m = 0; m < 48; m++) {
  1019. keys[11][m] = tempKey[m];
  1020. }
  1021. break;
  1022. case 12:
  1023. for (m = 0; m < 48; m++) {
  1024. keys[12][m] = tempKey[m];
  1025. }
  1026. break;
  1027. case 13:
  1028. for (m = 0; m < 48; m++) {
  1029. keys[13][m] = tempKey[m];
  1030. }
  1031. break;
  1032. case 14:
  1033. for (m = 0; m < 48; m++) {
  1034. keys[14][m] = tempKey[m];
  1035. }
  1036. break;
  1037. case 15:
  1038. for (m = 0; m < 48; m++) {
  1039. keys[15][m] = tempKey[m];
  1040. }
  1041. break;
  1042. }
  1043. }
  1044. return keys;
  1045. }
  1046. }
  1047.  
  1048. }

把信息存储到浏览器中还是加密的要好,虽然现在有不少在线解密工具,但是还是推荐加密

下面进入正题,如何清除Cookie?

在谈谈这个问题前,我们是如何使用js获取Cookie呢?

    function getMyCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
} <!-- 例如cookie的名字叫name 可通过getMyCookie("name")获得Cookie-->

Cookie通常是加密的,假如存储的Cookie是一个字符串,如何将其解密呢?

比如我使用的是DES加密和解密,我通过ajax获取它并将其解析出来?

代码如下:

js代码:

 //自动加载获取Cookie
function autoLoad(){ var str ="获取Cookie";
$.ajax({
url:"getCookie",
type:"POST",
data : {"str":str},
dataType : 'json',
success:function(data){ var json = eval("("+data+")"); if(json.returnCode=="200"){
$("#userId").val(json.userId); }else if(json.returnCode=="500"){
window.location.href='view/Login.html';
}else{
alert("有问题,请联系管理员");
} },error:function(){
alert("失败");
}
});
}

Java代码:

/**
* 获取Cookie信息
* @param str
* @param request
* @return
*/
@RequestMapping(value="/getCookie",method=RequestMethod.POST,produces="application/json;charset=utf-8")
@ResponseBody
public String getCookie(String str,HttpServletRequest request) {
logger.info("获取Cookie信息");
logger.info("str:"+str); Map<String,Object> map = new HashMap<String,Object>(); //获取Cookie
String cookie = CookieUtils.getCookie(request, "userId");
if(cookie!=""||cookie!=null) {
logger.info("Cookie:"+cookie);
//将Cookie解密
String userId = DesUtils.decode(cookie, "userId"); //打印Cookie解密
logger.info("userId:"+userId);
map.put("userId", userId);
map.put("returnMsg", "可获取Cookie");
map.put("returnCode", "200"); }else { map.put("returnMsg", "不能获取Cookie");
map.put("returnCode", "500"); }
return JSON.toJSONString(map);
}

  

如何清除Cookie?

代码如下所示:

我的存储用户信息是用Cookie,自然注销功能也是用清除Cookie的做法

/**
* 退出功能
*/
function getMyCookie(name){
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
return unescape(arr[2]);
else
return null;
} function delCookie(name){
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getMyCookie(name);
if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString()+";path=/";
}
//退出功能
$(function(){
$("#exit").click(function(){
delCookie("userId");
location.href="http://localhost:8080/blog-web/";
});
});

首先Cookie有如下优缺点:

优点:

(1)可配置到期规则 Cookie 可以在浏览器会话结束时到期,或者可以在客户端计算机上无限期存在,这取决于客户端的到期规则。

(2)不需要任何服务器资源 Cookie 存储在客户端并在发送后由服务器读取。

(3)简单性 Cookie 是一种基于文本的轻量结构,包含简单的键值对。

   (4)数据持久性 虽然客户端计算机上 Cookie 的持续时间取决于客户端上的 Cookie 过期处理和用户干预,Cookie 通常是客户端上持续时间最长的数据保留形式。

缺点:

  (1) 大小受到限制 大多数浏览器对 Cookie 的大小有 4096 字节的限制,尽管在当今新的浏览器和客户端设备版本中,支持 8192 字节的 Cookie 大小已愈发常见。

   (2)用户配置为禁用 有些用户禁用了浏览器或客户端设备接收 Cookie 的能力,因此限制了这一功能。

   (3) 潜在的安全风险 Cookie 可能会被篡改。用户可能会操纵其计算机上的 Cookie,这意味着会对安全性造成潜在风险或者导致依赖于 Cookie 的应用程序失败。另外,虽然 Cookie 只能被将它们发送到客户端的域访问,历史上黑客已经发现从用户计算机上的其他域访问 Cookie 的方法。您可以手动加密和解密 Cookie,但这需要额外的编码,并且因为加密和解密需要耗费一定的时间而影响应用程序的性能。

  

具体为什么要用Cookie结合业务需要。

对于我为什么用Cookie?而不用session,session存储服务器端,并不是全局的,而且随着用户越来越多,每个用户都有与之对应的session,对于服务器而言,无形之间形成了不小的并发。

而使用cookie,cookie虽然有安全方面的风险,但是是全局的,全局唯一一个cookie,只需将用户关键信息,例如id或用户名之类的存储其中,这样我每个页面都可以获取的到。这样实现拦截非法登录的效果也是很好的,而且无形之间减少了很多并发。当然就目前而言,对我来说,使用cookie不再向之前为了获取session,搞个拦截器过滤器,真的有种白了少年头,空悲切的感觉啊!

js之清除Cookie的更多相关文章

  1. JS 无法清除Cookie的解决方法

    JS 无法清除Cookie的解决方法   项目中使用sdmenu.js时,需要在登录时清除Cookie,而sdmenu默认是会保存Cookie的 下面是sdmenu.js保存Cookie的方法 doc ...

  2. 关于用js无法清除cookie

    cookie名称相同时,未必是同一个. 因为Domain(站点)不同,路径不同. 用jquery.cookie清除cookie时,应当加上path属性: $.cookie("MedicalU ...

  3. php,js清除cookie

    目的通过控制cookie中的是否有莫个值实现是否跳转重定向 http方式 <?php if ($_COOKIE['test'] == 1) {  echo 'have cookie test'; ...

  4. js清除cookie有时无法清除

    最近写页面遇到一个问题,退出的时候需要清除cookie,但是刚开始一直清除不掉,代码如下: //清除函数 function delCookie(name) { var date= new Date() ...

  5. js设置,取得,清除cookie

    //取得cookie function getCookie(name) {  var nameEQ = name + "=";  var ca = document.cookie. ...

  6. 【原创】js中利用cookie实现记住密码功能

    在登录界面添加记住密码功能,我首先想到的是在java后台中调用cookie存放账号密码,大致如下: HttpServletRequest request HttpServletResponse res ...

  7. js中的cookie使用

    在网上找到的资料,收藏一下 function getCookies(name) { var arr = document.cookie.match(new RegExp("(^| )&quo ...

  8. JS对浏览器Cookie的操作,查询、设置以及删除

    JavaScript是运行在客户端的脚本,因此一般是不能够设置Session的,因为Session是运行在服务器端的. 而cookie是运行在客户端的,所以可以用JS来设置cookie. 假设有这样一 ...

  9. JS 详解 Cookie、 LocalStorage 与 SessionStorage-转载

    记录一下这些知识,有时候用到会忘记,对原文作者表达感谢. 附上原文链接:JS 详解 Cookie. LocalStorage 与 SessionStorage 基本概念 Cookie Cookie 是 ...

随机推荐

  1. Yarn的运行原理(执行流程)

    服务功能 ResouceManager:     1.处理客户端的请求     2.启动和监控ApplicationMaster     3.监控nodemanager     4.资源的分配和调度 ...

  2. Java框架之Spring(一)

    在学习Spring之前,需要回忆一下工厂模式.下面会演示一段代码,自己体会.之所以要工厂模式是因为他有一个好处,很像Spring的用法.在实际开发中,new对象对于一个开发人员来说是一件非常需要小心谨 ...

  3. LoadRunner接口测试标准模板

    Action() { int nHttpRetCode; // 默认最大长度为256,get请求需注意缓存问题,需要根据content-length进行修改 web_set_max_html_para ...

  4. JavaScript基础要点

    一.值和类型及运算 JavaScript中的六种基本值类型 数字(number).字符串(string).布尔值(boolean).对象(object).函数(function).未定义类型(unde ...

  5. Layui tree 下拉菜单树

    1.效果: 2.html  代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" ...

  6. Jetbrains IDE 中 compass sass 设置

    环境 Ubuntu 13.10 1. 安装ruby sudo apt-get install ruby 如果后面安装 compass 时遇到安装失败,提示:“[Ubuntu] ERROR: Faile ...

  7. 一次关于()=>({})的使用

    今天遇到了一个问题,值得一记 首先在我看项目代码时发现了一个问题 有一个JS的export如下 大家可以注意一下config 这里为什么要如此写法呢? 首先这里用的时ES6的箭头函数 ()=>{ ...

  8. 【工具相关】Web-Sublime Text2-安装插件HTMLPrettify

    一,打开Sublime Text2---->Preferences--->Browse Packages.--->查看Sublime Text2已经有的插件.如图所示. 二,在网上下 ...

  9. 利用python和shell脚本生成train.txt的标签文件

    1. 用shell脚本生成带绝对路径的train.txt 例如我要生成如下形式的带标签的文件,如图:(如有两个标签:0 和 1) shell脚本如下: 这样标签0写入了train.txt # /usr ...

  10. 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]

    基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]   by:授客 QQ:1033553122 由于篇幅问题,,暂且采用网盘分享的形式: 下载地址: [授客] ...