pass.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. function randomWord(randomFlag: boolean, min: number, max: number = 15) {
  2. let str = '';
  3. let range = min;
  4. const arr = [
  5. '0',
  6. '1',
  7. '2',
  8. '3',
  9. '4',
  10. '5',
  11. '6',
  12. '7',
  13. '8',
  14. '9',
  15. 'a',
  16. 'b',
  17. 'c',
  18. 'd',
  19. 'e',
  20. 'f',
  21. 'g',
  22. 'h',
  23. 'i',
  24. 'j',
  25. 'k',
  26. 'l',
  27. 'm',
  28. 'n',
  29. 'o',
  30. 'p',
  31. 'q',
  32. 'r',
  33. 's',
  34. 't',
  35. 'u',
  36. 'v',
  37. 'w',
  38. 'x',
  39. 'y',
  40. 'z',
  41. 'A',
  42. 'B',
  43. 'C',
  44. 'D',
  45. 'E',
  46. 'F',
  47. 'G',
  48. 'H',
  49. 'I',
  50. 'J',
  51. 'K',
  52. 'L',
  53. 'M',
  54. 'N',
  55. 'O',
  56. 'P',
  57. 'Q',
  58. 'R',
  59. 'S',
  60. 'T',
  61. 'U',
  62. 'V',
  63. 'W',
  64. 'X',
  65. 'Y',
  66. 'Z',
  67. ];
  68. // 随机产生
  69. if (randomFlag) {
  70. range = Math.round(Math.random() * (max - min)) + min;
  71. }
  72. for (var i = 0; i < range; i++) {
  73. const pos = Math.round(Math.random() * (arr.length - 1));
  74. str += arr[pos];
  75. }
  76. return str;
  77. }
  78. // 密码加密
  79. export const passWordJia = (strTemp: string, strv = '') => {
  80. const str = btoa(unescape(encodeURIComponent(strTemp)));
  81. const NUM = 2;
  82. const front = randomWord(false, 8);
  83. const middle = randomWord(false, 8);
  84. const end = randomWord(false, 8);
  85. const str1 = str.substring(0, NUM);
  86. const str2 = str.substring(NUM);
  87. if (strv) {
  88. const strv1 = strv.substring(0, NUM);
  89. const strv2 = strv.substring(NUM);
  90. return [front + str2 + middle + str1 + end, front + strv2 + middle + strv1 + end];
  91. }
  92. const txt = front + str2 + middle + str1 + end;
  93. return txt;
  94. };
  95. // 密码解密
  96. export const passWordJie = (str: any) => {
  97. const NUM = 2;
  98. const str1 = str.substring(8);
  99. const str2 = str1.substring(0, str1.length - 8);
  100. const front = str2.slice(-NUM);
  101. const end = str2.substring(0, str2.length - 8 - NUM);
  102. const txt = front + end;
  103. return decodeURIComponent(escape(atob(txt)));
  104. };