星火管控前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

secret.js 948B

12345678910111213141516171819202122232425262728293031323334
  1. let keystr = "XINGHUOLIAOYUAN7"; //密钥
  2. // 字符串转hex
  3. let string_to_hex = function (str) {
  4. let tempstr = "";
  5. for (let i = 0; i < str.length; i++) {
  6. if (tempstr === "") tempstr = str.charCodeAt(i).toString(16);
  7. else tempstr += str.charCodeAt(i).toString(16);
  8. }
  9. return tempstr;
  10. };
  11. let key = string_to_hex(keystr);
  12. key = CryptoJS.enc.Hex.parse(key);
  13. // 加密
  14. const getEncryptedString = (src) => {
  15. const enc = CryptoJS.AES.encrypt(src, key, {
  16. mode: CryptoJS.mode.ECB,
  17. padding: CryptoJS.pad.Pkcs7
  18. });
  19. const enced = enc.ciphertext.toString();
  20. return enced;
  21. };
  22. // 解密
  23. const getDecryptString = (enced) => {
  24. const dec = CryptoJS.AES.decrypt(CryptoJS.format.Hex.parse(enced), key, {
  25. mode: CryptoJS.mode.ECB,
  26. padding: CryptoJS.pad.Pkcs7
  27. });
  28. let decstr = CryptoJS.enc.Utf8.stringify(dec);
  29. return decstr;
  30. };
  31. window.getEncryptedString = getEncryptedString;
  32. window.getDecryptString = getDecryptString;