lanControlAuthenticationUtils.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var crypto_js_1 = __importDefault(require("crypto-js"));
  7. var logger_1 = require("./logger");
  8. var LanControlAuthenticationUtils = (function () {
  9. function LanControlAuthenticationUtils() {
  10. }
  11. LanControlAuthenticationUtils.encryptionData = function (_a) {
  12. var iv = _a.iv, key = _a.key, data = _a.data;
  13. try {
  14. var cipher = crypto_js_1.default.AES.encrypt(data, crypto_js_1.default.MD5(key), {
  15. iv: crypto_js_1.default.enc.Utf8.parse(iv),
  16. mode: crypto_js_1.default.mode.CBC,
  17. padding: crypto_js_1.default.pad.Pkcs7,
  18. });
  19. var base64Cipher = cipher.ciphertext.toString(crypto_js_1.default.enc.Base64);
  20. return base64Cipher;
  21. }
  22. catch (e) {
  23. logger_1.logger.error("encryptionData error: ".concat(e));
  24. }
  25. };
  26. LanControlAuthenticationUtils.decryptionData = function (_a) {
  27. var iv = _a.iv, key = _a.key, data = _a.data;
  28. var bytes = crypto_js_1.default.AES.decrypt(data, crypto_js_1.default.MD5(key), {
  29. iv: crypto_js_1.default.enc.Utf8.parse(iv),
  30. mode: crypto_js_1.default.mode.CBC,
  31. padding: crypto_js_1.default.pad.Pkcs7,
  32. });
  33. var decryptedData = bytes.toString(crypto_js_1.default.enc.Utf8);
  34. return decryptedData;
  35. };
  36. LanControlAuthenticationUtils.encryptionBase64 = function (str) {
  37. return crypto_js_1.default.enc.Base64.stringify(crypto_js_1.default.enc.Utf8.parse(str));
  38. };
  39. LanControlAuthenticationUtils.decryptionBase64 = function (base64Str) {
  40. return crypto_js_1.default.enc.Base64.parse(base64Str).toString(crypto_js_1.default.enc.Utf8);
  41. };
  42. return LanControlAuthenticationUtils;
  43. }());
  44. exports.default = LanControlAuthenticationUtils;