@lingxiteam/assets 0.8.30-alpha.6 → 0.9.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/security/fetch.d.ts +2 -6
- package/es/security/fetch.js +11 -230
- package/es/security/httpEncryption.js +5 -19
- package/es/security/index.d.ts +4 -11
- package/es/security/index.js +1 -5
- package/es/security/{encipher/sign.d.ts → sign.d.ts} +0 -0
- package/es/security/{encipher/sign.js → sign.js} +2 -2
- package/es/utils/url.d.ts +0 -1
- package/es/utils/url.js +0 -31
- package/package.json +2 -4
- package/es/security/const.d.ts +0 -14
- package/es/security/const.js +0 -16
- package/es/security/encipher/aes.d.ts +0 -2
- package/es/security/encipher/aes.js +0 -28
- package/es/security/encipher/des.d.ts +0 -2
- package/es/security/encipher/des.js +0 -27
- package/es/security/encipher/rsa.d.ts +0 -2
- package/es/security/encipher/rsa.js +0 -19
- package/es/security/store.d.ts +0 -1
- package/es/security/store.js +0 -61
package/es/security/fetch.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
declare const fetch: (url: any, fetchOptions?: any, config?: {
|
|
2
|
-
mode
|
|
3
|
-
signKeyOptions
|
|
4
|
-
aesOptions?: any;
|
|
5
|
-
desOptions?: any;
|
|
6
|
-
rsaOptions?: any;
|
|
7
|
-
debug?: boolean;
|
|
2
|
+
mode: string;
|
|
3
|
+
signKeyOptions: any;
|
|
8
4
|
}) => Promise<Response>;
|
|
9
5
|
export default fetch;
|
package/es/security/fetch.js
CHANGED
|
@@ -1,248 +1,29 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
|
|
3
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
4
|
-
|
|
5
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6
|
-
|
|
7
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
8
|
-
|
|
9
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10
|
-
|
|
11
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
2
|
|
|
13
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
4
|
|
|
15
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
16
6
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
24
|
-
|
|
25
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
26
|
-
|
|
27
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
-
|
|
29
|
-
import { createHttpSignStr } from './encipher/sign';
|
|
30
|
-
import { RSAEncrypt, RSADecrypt } from './encipher/rsa';
|
|
31
|
-
import { AESEncrypt, AESDecrypt } from './encipher/aes';
|
|
32
|
-
import { DESEncrypt, DESDecrypt } from './encipher/des';
|
|
33
|
-
import { MODE, signKey, aesKey, rsaPublicKey, rsaPrivKey, desKey, securityHeaderKey } from './const'; // import { store } from './store';
|
|
34
|
-
|
|
35
|
-
var originFetch = window.fetch; // const debugData = store('debugData');
|
|
36
|
-
// (window as any).debugData = debugData;
|
|
37
|
-
|
|
38
|
-
var LXREQ = {};
|
|
39
|
-
window.LXREQ = LXREQ;
|
|
40
|
-
|
|
41
|
-
function encryptedStr(str, type) {
|
|
42
|
-
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
43
|
-
|
|
44
|
-
if (type === MODE.AES) {
|
|
45
|
-
var _config$aesOptions, _config$aesOptions2;
|
|
46
|
-
|
|
47
|
-
return AESEncrypt(str, ((_config$aesOptions = config.aesOptions) === null || _config$aesOptions === void 0 ? void 0 : _config$aesOptions.key) || aesKey, (_config$aesOptions2 = config.aesOptions) === null || _config$aesOptions2 === void 0 ? void 0 : _config$aesOptions2.encrypt);
|
|
48
|
-
} else if (type === MODE.RSA) {
|
|
49
|
-
var _config$rsaOptions, _config$rsaOptions2;
|
|
50
|
-
|
|
51
|
-
return RSAEncrypt(str, ((_config$rsaOptions = config.rsaOptions) === null || _config$rsaOptions === void 0 ? void 0 : _config$rsaOptions.publicKey) || rsaPublicKey, (_config$rsaOptions2 = config.rsaOptions) === null || _config$rsaOptions2 === void 0 ? void 0 : _config$rsaOptions2.encrypt);
|
|
52
|
-
} else if (type === MODE.DES) {
|
|
53
|
-
var _config$desOptions, _config$desOptions2;
|
|
54
|
-
|
|
55
|
-
return DESEncrypt(str, ((_config$desOptions = config.desOptions) === null || _config$desOptions === void 0 ? void 0 : _config$desOptions.key) || desKey, (_config$desOptions2 = config.desOptions) === null || _config$desOptions2 === void 0 ? void 0 : _config$desOptions2.encrypt);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return str;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function decryptedStr(str, type) {
|
|
62
|
-
var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
63
|
-
|
|
64
|
-
if (type === MODE.AES) {
|
|
65
|
-
var _config$aesOptions3, _config$aesOptions4;
|
|
66
|
-
|
|
67
|
-
return AESDecrypt(str, ((_config$aesOptions3 = config.aesOptions) === null || _config$aesOptions3 === void 0 ? void 0 : _config$aesOptions3.key) || aesKey, (_config$aesOptions4 = config.aesOptions) === null || _config$aesOptions4 === void 0 ? void 0 : _config$aesOptions4.decrypt);
|
|
68
|
-
} else if (type === MODE.RSA) {
|
|
69
|
-
var _config$rsaOptions3, _config$rsaOptions4;
|
|
70
|
-
|
|
71
|
-
return RSADecrypt(str, ((_config$rsaOptions3 = config.rsaOptions) === null || _config$rsaOptions3 === void 0 ? void 0 : _config$rsaOptions3.privKey) || rsaPrivKey, (_config$rsaOptions4 = config.rsaOptions) === null || _config$rsaOptions4 === void 0 ? void 0 : _config$rsaOptions4.decrypt) || '';
|
|
72
|
-
} else if (type === MODE.DES) {
|
|
73
|
-
var _config$desOptions3, _config$desOptions4;
|
|
74
|
-
|
|
75
|
-
return DESDecrypt(str, ((_config$desOptions3 = config.desOptions) === null || _config$desOptions3 === void 0 ? void 0 : _config$desOptions3.key) || desKey, (_config$desOptions4 = config.desOptions) === null || _config$desOptions4 === void 0 ? void 0 : _config$desOptions4.decrypt);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return str;
|
|
79
|
-
} // 统一请求参数加密
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
function encrypted(url, opts, type) {
|
|
83
|
-
var config = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
84
|
-
var reqId = arguments.length > 4 ? arguments[4] : undefined;
|
|
85
|
-
var isFormData = opts.body instanceof FormData;
|
|
86
|
-
var headerReqId = reqId ? {
|
|
87
|
-
'LX-REQ-ID': "LXREQ.".concat(reqId)
|
|
88
|
-
} : {}; // search 部分加密
|
|
89
|
-
|
|
90
|
-
var encryptedUrl = url.indexOf('?') !== -1 ? url.replace(/(?!\?)([^?])+$/g, function (search) {
|
|
91
|
-
var params = search.split('&').map(function (param) {
|
|
92
|
-
var _param$split = param.split('='),
|
|
93
|
-
_param$split2 = _slicedToArray(_param$split, 2),
|
|
94
|
-
k = _param$split2[0],
|
|
95
|
-
v = _param$split2[1];
|
|
96
|
-
|
|
97
|
-
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(encryptedStr(v, type, config)));
|
|
98
|
-
});
|
|
99
|
-
return params.join('&');
|
|
100
|
-
}) : url; // body参数加密
|
|
101
|
-
|
|
102
|
-
var encryptedOpts = Object.assign({}, opts);
|
|
103
|
-
encryptedOpts.headers = _objectSpread(_objectSpread(_objectSpread({}, opts.headers), headerReqId), {}, _defineProperty({}, securityHeaderKey, type));
|
|
104
|
-
|
|
105
|
-
if (isFormData) {
|
|
106
|
-
// formData 加密
|
|
107
|
-
var formData = new FormData();
|
|
108
|
-
var reqBody = opts.body;
|
|
109
|
-
|
|
110
|
-
var _iterator = _createForOfIteratorHelper(reqBody.keys()),
|
|
111
|
-
_step;
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
115
|
-
var key = _step.value;
|
|
116
|
-
var value = reqBody.get(key);
|
|
117
|
-
formData.append(key, encryptedStr(value, type, config));
|
|
118
|
-
}
|
|
119
|
-
} catch (err) {
|
|
120
|
-
_iterator.e(err);
|
|
121
|
-
} finally {
|
|
122
|
-
_iterator.f();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
encryptedOpts.body = formData;
|
|
126
|
-
} else if (opts.body) {
|
|
127
|
-
// 文本加密
|
|
128
|
-
encryptedOpts.body = encryptedStr(opts.body, type, config);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return [encryptedUrl, encryptedOpts];
|
|
132
|
-
} // 将解密数据
|
|
133
|
-
// function debugRecords(id: string, value: any) {
|
|
134
|
-
// // sessionStorage.setItem(id, JSON.stringify(value));
|
|
135
|
-
// Object.defineProperty(LXREQ, id, {
|
|
136
|
-
// get() {
|
|
137
|
-
// // debugData.show(id)
|
|
138
|
-
// return '';
|
|
139
|
-
// },
|
|
140
|
-
// });
|
|
141
|
-
// }
|
|
7
|
+
import { createHttpSignStr } from './sign';
|
|
8
|
+
var originFetch = window.fetch;
|
|
9
|
+
var defaultSignKey = 'X-SIGN';
|
|
10
|
+
var MODE = {
|
|
11
|
+
SIGN_KEY: 'signKey' // 参数签名
|
|
142
12
|
|
|
13
|
+
};
|
|
14
|
+
var envKey = process.env.LING_XI_HTTP_SIGN_HEADER_KEY || process.env.REACT_APP_HTTP_SIGN_HEADER_KEY || process.env.UMI_APP_HTTP_SIGN_HEADER_KEY || process.env.FISHX_APP_HTTP_SIGN_HEADER_KEY;
|
|
143
15
|
|
|
144
16
|
var fetch = function fetch(url) {
|
|
145
17
|
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
146
|
-
var config = arguments.length > 2
|
|
18
|
+
var config = arguments.length > 2 ? arguments[2] : undefined;
|
|
147
19
|
|
|
148
20
|
var opts = _objectSpread({}, fetchOptions);
|
|
149
21
|
|
|
150
|
-
|
|
151
|
-
var isDebug = (config === null || config === void 0 ? void 0 : config.debug) || window.lxDebug || !!window.localStorage.getItem('lxDebug') || true; // ------ 参数签名(默认) ------
|
|
152
|
-
|
|
153
|
-
if ( // 配置开启加密
|
|
154
|
-
(config.mode === MODE.SIGN_KEY || config.mode === MODE.SIGN) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledSignKey) !== true || // 请求头开启加密
|
|
155
|
-
optSecurityHeaderKey === '1.0') {
|
|
22
|
+
if ((!config || !config.mode || config.mode === MODE.SIGN_KEY) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledSignKey) !== true) {
|
|
156
23
|
var _config$signKeyOption;
|
|
157
24
|
|
|
158
|
-
opts.headers = _objectSpread(_objectSpread({}, opts.headers), {}, _defineProperty({}, (config === null || config === void 0 ? void 0 : (_config$signKeyOption = config.signKeyOptions) === null || _config$signKeyOption === void 0 ? void 0 : _config$signKeyOption.key) ||
|
|
159
|
-
|
|
160
|
-
} // ------ 参数加密 ------
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if ((config.mode === MODE.RSA || config.mode === MODE.AES) && (fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.disabledEncrypted) !== true || optSecurityHeaderKey === '2.0' || optSecurityHeaderKey === '3.0' || optSecurityHeaderKey === '4.0') {
|
|
164
|
-
// 标记请求ID,用于获取解密数据
|
|
165
|
-
var reqId = "XA".concat(+new Date()); // search和body加密
|
|
166
|
-
|
|
167
|
-
var _encrypted = encrypted(url, opts, config.mode || optSecurityHeaderKey, config, reqId),
|
|
168
|
-
_encrypted2 = _slicedToArray(_encrypted, 2),
|
|
169
|
-
encryptedUrl = _encrypted2[0],
|
|
170
|
-
encryptedOpts = _encrypted2[1];
|
|
171
|
-
|
|
172
|
-
return originFetch(encryptedUrl, encryptedOpts).then( /*#__PURE__*/function () {
|
|
173
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
|
|
174
|
-
var securityType, respResult, result, json, blob;
|
|
175
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
176
|
-
while (1) {
|
|
177
|
-
switch (_context.prev = _context.next) {
|
|
178
|
-
case 0:
|
|
179
|
-
// 响应解密
|
|
180
|
-
securityType = response.headers.get(securityHeaderKey);
|
|
181
|
-
|
|
182
|
-
if (!(securityType && response.body)) {
|
|
183
|
-
_context.next = 22;
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
_context.next = 4;
|
|
188
|
-
return response.text();
|
|
189
|
-
|
|
190
|
-
case 4:
|
|
191
|
-
respResult = _context.sent;
|
|
192
|
-
_context.prev = 5;
|
|
193
|
-
result = decryptedStr(respResult, securityType, config);
|
|
194
|
-
_context.next = 18;
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case 9:
|
|
198
|
-
_context.prev = 9;
|
|
199
|
-
_context.t0 = _context["catch"](5);
|
|
200
|
-
console.error('--------解密失败--------');
|
|
201
|
-
console.error("\u8BF7\u6C42ID\uFF1A".concat(reqId));
|
|
202
|
-
console.error("\u8BF7\u6C42\u5730\u5740\uFF1A".concat(url));
|
|
203
|
-
console.error("\u89E3\u5BC6\u65B9\u5F0F\uFF1A".concat(securityType));
|
|
204
|
-
console.error("\u89E3\u5BC6\u62A5\u6587\uFF1A".concat(respResult));
|
|
205
|
-
console.error("\u5931\u8D25\u539F\u56E0\uFF1A".concat(_context.t0));
|
|
206
|
-
return _context.abrupt("return", new Response(null, {
|
|
207
|
-
status: 400,
|
|
208
|
-
statusText: String(_context.t0)
|
|
209
|
-
}));
|
|
210
|
-
|
|
211
|
-
case 18:
|
|
212
|
-
// 开启调试模式,记录解密数据
|
|
213
|
-
if (isDebug || true) {// debugRecords(reqId, result);
|
|
214
|
-
} // 覆盖响应值
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
try {
|
|
218
|
-
json = JSON.parse(result);
|
|
219
|
-
} catch (e) {
|
|
220
|
-
json = result;
|
|
221
|
-
console.warn("reqId: ".concat(reqId, " \u8F6C\u6362JSON\u5931\u8D25, \u5185\u5BB9\u4E3A"), result);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
blob = new Blob([JSON.stringify(json, null, 2)], {
|
|
225
|
-
type: 'application/json'
|
|
226
|
-
});
|
|
227
|
-
return _context.abrupt("return", new Response(blob));
|
|
228
|
-
|
|
229
|
-
case 22:
|
|
230
|
-
return _context.abrupt("return", response);
|
|
231
|
-
|
|
232
|
-
case 23:
|
|
233
|
-
case "end":
|
|
234
|
-
return _context.stop();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}, _callee, null, [[5, 9]]);
|
|
238
|
-
}));
|
|
239
|
-
|
|
240
|
-
return function (_x) {
|
|
241
|
-
return _ref.apply(this, arguments);
|
|
242
|
-
};
|
|
243
|
-
}());
|
|
244
|
-
} // 其他
|
|
245
|
-
|
|
25
|
+
opts.headers = _objectSpread(_objectSpread({}, opts.headers), {}, _defineProperty({}, (config === null || config === void 0 ? void 0 : (_config$signKeyOption = config.signKeyOptions) === null || _config$signKeyOption === void 0 ? void 0 : _config$signKeyOption.key) || envKey || defaultSignKey, createHttpSignStr(url, fetchOptions)));
|
|
26
|
+
}
|
|
246
27
|
|
|
247
28
|
return originFetch(url, opts);
|
|
248
29
|
};
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// 使用方式1: 使用fetch请求模块,start({ mode: signKey }),适应经过封装的fetch模块
|
|
10
10
|
// 使用方式2: 使用fetch请求模块,将window.fetch 替换成 fetch,适应自己封装的fetch模块
|
|
11
11
|
// 使用方式3: 不使用fetch请求模块,使用createHttpSignStr自己获取签名,自行在header上添加参数
|
|
12
|
-
import { createHttpSignStr } from './
|
|
12
|
+
import { createHttpSignStr } from './sign'; // eslint-disable-next-line import/no-named-as-default, import/no-named-as-default-member
|
|
13
13
|
|
|
14
14
|
import fetch from './fetch';
|
|
15
15
|
var isHttpEncryption = false;
|
|
@@ -17,15 +17,9 @@ var originFetch = window.fetch;
|
|
|
17
17
|
|
|
18
18
|
function start(_ref) {
|
|
19
19
|
var _ref$mode = _ref.mode,
|
|
20
|
-
mode = _ref$mode === void 0 ? '
|
|
20
|
+
mode = _ref$mode === void 0 ? '' : _ref$mode,
|
|
21
21
|
_ref$signKeyOptions = _ref.signKeyOptions,
|
|
22
|
-
signKeyOptions = _ref$signKeyOptions === void 0 ? {} : _ref$signKeyOptions
|
|
23
|
-
_ref$aesOptions = _ref.aesOptions,
|
|
24
|
-
aesOptions = _ref$aesOptions === void 0 ? {} : _ref$aesOptions,
|
|
25
|
-
_ref$desOptions = _ref.desOptions,
|
|
26
|
-
desOptions = _ref$desOptions === void 0 ? {} : _ref$desOptions,
|
|
27
|
-
_ref$rsaOptions = _ref.rsaOptions,
|
|
28
|
-
rsaOptions = _ref$rsaOptions === void 0 ? {} : _ref$rsaOptions;
|
|
22
|
+
signKeyOptions = _ref$signKeyOptions === void 0 ? {} : _ref$signKeyOptions;
|
|
29
23
|
|
|
30
24
|
if (!mode) {
|
|
31
25
|
console.error('http加密开启失败,缺少mode参数');
|
|
@@ -35,12 +29,7 @@ function start(_ref) {
|
|
|
35
29
|
if (isHttpEncryption) return true;
|
|
36
30
|
|
|
37
31
|
switch (mode) {
|
|
38
|
-
case 'signKey':
|
|
39
|
-
|
|
40
|
-
case '1.0':
|
|
41
|
-
case '2.0':
|
|
42
|
-
case '3.0':
|
|
43
|
-
case '4.0':
|
|
32
|
+
case 'signKey':
|
|
44
33
|
{
|
|
45
34
|
if (typeof window.fetch === 'function') {
|
|
46
35
|
isHttpEncryption = true;
|
|
@@ -49,10 +38,7 @@ function start(_ref) {
|
|
|
49
38
|
var fetchOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
50
39
|
return fetch(url, fetchOptions, {
|
|
51
40
|
mode: mode,
|
|
52
|
-
signKeyOptions: signKeyOptions
|
|
53
|
-
aesOptions: aesOptions,
|
|
54
|
-
desOptions: desOptions,
|
|
55
|
-
rsaOptions: rsaOptions
|
|
41
|
+
signKeyOptions: signKeyOptions
|
|
56
42
|
});
|
|
57
43
|
};
|
|
58
44
|
} else {
|
package/es/security/index.d.ts
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
httpEncryption: {
|
|
3
|
-
start: ({ mode, signKeyOptions
|
|
3
|
+
start: ({ mode, signKeyOptions }: {
|
|
4
4
|
mode?: string | undefined;
|
|
5
5
|
signKeyOptions?: {} | undefined;
|
|
6
|
-
aesOptions?: {} | undefined;
|
|
7
|
-
desOptions?: {} | undefined;
|
|
8
|
-
rsaOptions?: {} | undefined;
|
|
9
6
|
}) => boolean;
|
|
10
7
|
stop: () => void;
|
|
11
8
|
fetch: (url: any, fetchOptions?: any, config?: {
|
|
12
|
-
mode
|
|
13
|
-
signKeyOptions
|
|
14
|
-
|
|
15
|
-
desOptions?: any;
|
|
16
|
-
rsaOptions?: any;
|
|
17
|
-
debug?: boolean | undefined;
|
|
18
|
-
}) => Promise<Response>;
|
|
9
|
+
mode: string;
|
|
10
|
+
signKeyOptions: any;
|
|
11
|
+
} | undefined) => Promise<Response>;
|
|
19
12
|
createHttpSignStr: (url: string, options: any) => string;
|
|
20
13
|
};
|
|
21
14
|
sign: {
|
package/es/security/index.js
CHANGED
|
File without changes
|
|
@@ -13,7 +13,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
14
|
|
|
15
15
|
import { sha256 } from 'js-sha256';
|
|
16
|
-
import { obj2QueryString } from '
|
|
16
|
+
import { obj2QueryString } from '../utils/url';
|
|
17
17
|
var SIGN_KEY = process.env.LING_XI_HTTP_SIGN_KEY || 'zrT5bi2escXilaH1fs653uZiH9RWfzCS'; // 1、签名算法:
|
|
18
18
|
// 通过对url、参数、秘钥拼接成字符串,然后对字符串使用算法SHA-256得到64个字符串,放到header, X-SIGN=XXXXXXX。
|
|
19
19
|
// 2、签名字符串拼接规则:
|
|
@@ -129,7 +129,7 @@ export var createHttpSignStr = function createHttpSignStr(url, options) {
|
|
|
129
129
|
|
|
130
130
|
var str = [apiPath, headerParams, params, SIGN_KEY].join('#');
|
|
131
131
|
|
|
132
|
-
if (typeof window !== 'undefined' && (window.
|
|
132
|
+
if (typeof window !== 'undefined' && (window.signDebug || window.localStorage.getItem('signDebug'))) {
|
|
133
133
|
console.log(' --- signDebug ---');
|
|
134
134
|
console.log('url', url);
|
|
135
135
|
console.log('str', str);
|
package/es/utils/url.d.ts
CHANGED
package/es/utils/url.js
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
1
|
export var obj2QueryString = function obj2QueryString(params) {
|
|
14
2
|
var queryString = Object.keys(params).map(function (key) {
|
|
15
3
|
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key]));
|
|
16
4
|
}).join('&');
|
|
17
5
|
return queryString;
|
|
18
|
-
};
|
|
19
|
-
export var getSearchObj = function getSearchObj() {
|
|
20
|
-
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.href;
|
|
21
|
-
var urlArr = url.split('?');
|
|
22
|
-
if (urlArr.length === 1) return {};
|
|
23
|
-
var search = urlArr.pop() || '';
|
|
24
|
-
var objs = search.split('&');
|
|
25
|
-
var obj = {};
|
|
26
|
-
objs.forEach(function (value) {
|
|
27
|
-
var _value$split = value.split('='),
|
|
28
|
-
_value$split2 = _slicedToArray(_value$split, 2),
|
|
29
|
-
k = _value$split2[0],
|
|
30
|
-
v = _value$split2[1];
|
|
31
|
-
|
|
32
|
-
if (v) {
|
|
33
|
-
obj[decodeURIComponent(k)] = decodeURIComponent(v);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return obj;
|
|
37
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxiteam/assets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.30",
|
|
4
4
|
"description": "灵犀低代码平台移动端 - 工具类",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -35,8 +35,6 @@
|
|
|
35
35
|
},
|
|
36
36
|
"gitHead": "bcd338198e2c14459538542d10600ab03abc92f2",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"js-sha256": "^0.9.0",
|
|
40
|
-
"jsencrypt": "^3.1.0"
|
|
38
|
+
"js-sha256": "^0.9.0"
|
|
41
39
|
}
|
|
42
40
|
}
|
package/es/security/const.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const securityHeaderKey = "XA-TYPE";
|
|
2
|
-
export declare const defaultSignKey = "X-SIGN";
|
|
3
|
-
export declare const MODE: {
|
|
4
|
-
SIGN_KEY: string;
|
|
5
|
-
SIGN: string;
|
|
6
|
-
RSA: string;
|
|
7
|
-
AES: string;
|
|
8
|
-
DES: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const signKey: string;
|
|
11
|
-
export declare const rsaPublicKey: string | undefined;
|
|
12
|
-
export declare const rsaPrivKey: string | undefined;
|
|
13
|
-
export declare const aesKey: string;
|
|
14
|
-
export declare const desKey: string;
|
package/es/security/const.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var defaultAESKey = 'd86d7bab3d6ac01a';
|
|
2
|
-
var defaultDESKey = '91THRABY';
|
|
3
|
-
export var securityHeaderKey = 'XA-TYPE';
|
|
4
|
-
export var defaultSignKey = 'X-SIGN';
|
|
5
|
-
export var MODE = {
|
|
6
|
-
SIGN_KEY: 'signKey',
|
|
7
|
-
SIGN: '1.0',
|
|
8
|
-
RSA: '2.0',
|
|
9
|
-
AES: '3.0',
|
|
10
|
-
DES: '4.0'
|
|
11
|
-
};
|
|
12
|
-
export var signKey = process.env.LINGXI_HTTP_SIGN_HEADER_KEY || process.env.REACT_APP_HTTP_SIGN_HEADER_KEY || process.env.UMI_APP_HTTP_SIGN_HEADER_KEY || process.env.FISHX_APP_HTTP_SIGN_HEADER_KEY || defaultSignKey;
|
|
13
|
-
export var rsaPublicKey = process.env.LINGXI_HTTP_RSA_PUBLIC_KEY || process.env.REACT_APP_HTTP_RSA_PUBLIC_KEY || process.env.UMI_APP_HTTP_RSA_PUBLIC_KEY || process.env.FISHX_APP_HTTP_RSA_PUBLIC_KEY;
|
|
14
|
-
export var rsaPrivKey = process.env.LINGXI_HTTP_RSA_PRIV_KEY || process.env.REACT_APP_HTTP_RSA_PRIV_KEY || process.env.UMI_APP_HTTP_RSA_PRIV_KEY || process.env.FISHX_APP_HTTP_RSA_PRIV_KEY;
|
|
15
|
-
export var aesKey = process.env.LINGXI_HTTP_AES_KEY || process.env.REACT_APP_HTTP_AES_KEY || process.env.UMI_APP_HTTP_AES_KEY || process.env.FISHX_APP_HTTP_AES_KEY || defaultAESKey;
|
|
16
|
-
export var desKey = process.env.LINGXI_HTTP_DES_KEY || process.env.REACT_APP_HTTP_DES_KEY || process.env.UMI_APP_HTTP_DES_KEY || process.env.FISHX_APP_HTTP_DES_KEY || defaultDESKey;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import CryptoJS from 'crypto-js';
|
|
2
|
-
export var AESEncrypt = function AESEncrypt(value, aesKey, handle) {
|
|
3
|
-
if (typeof handle === 'function') {
|
|
4
|
-
return handle(value, aesKey, CryptoJS);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
var key = CryptoJS.enc.Utf8.parse(aesKey);
|
|
8
|
-
var ciphertext = CryptoJS.enc.Utf8.parse(value);
|
|
9
|
-
var encrypted = CryptoJS.AES.encrypt(ciphertext, key, {
|
|
10
|
-
mode: CryptoJS.mode.ECB,
|
|
11
|
-
padding: CryptoJS.pad.Pkcs7
|
|
12
|
-
});
|
|
13
|
-
return encrypted.toString();
|
|
14
|
-
};
|
|
15
|
-
export var AESDecrypt = function AESDecrypt(value, aesKey, handle) {
|
|
16
|
-
if (typeof handle === 'function') {
|
|
17
|
-
return handle(value, aesKey, CryptoJS);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var key = CryptoJS.enc.Utf8.parse(aesKey);
|
|
21
|
-
var ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(value)); // const ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(CryptoJS.enc.Utf8.parse(value).toString(CryptoJS.enc.Utf8)));
|
|
22
|
-
|
|
23
|
-
var encrypted = CryptoJS.AES.decrypt(ciphertext, key, {
|
|
24
|
-
mode: CryptoJS.mode.ECB,
|
|
25
|
-
padding: CryptoJS.pad.Pkcs7
|
|
26
|
-
});
|
|
27
|
-
return encrypted.toString(CryptoJS.enc.Utf8);
|
|
28
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import CryptoJS from 'crypto-js';
|
|
2
|
-
export var DESEncrypt = function DESEncrypt(value, aesKey, handle) {
|
|
3
|
-
if (typeof handle === 'function') {
|
|
4
|
-
return handle(value, aesKey, CryptoJS);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
var key = CryptoJS.enc.Utf8.parse(aesKey);
|
|
8
|
-
var ciphertext = CryptoJS.enc.Utf8.parse(value);
|
|
9
|
-
var encrypted = CryptoJS.DES.encrypt(ciphertext, key, {
|
|
10
|
-
mode: CryptoJS.mode.ECB,
|
|
11
|
-
padding: CryptoJS.pad.Pkcs7
|
|
12
|
-
});
|
|
13
|
-
return encrypted.toString();
|
|
14
|
-
};
|
|
15
|
-
export var DESDecrypt = function DESDecrypt(value, aesKey, handle) {
|
|
16
|
-
if (typeof handle === 'function') {
|
|
17
|
-
return handle(value, aesKey, CryptoJS);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
var key = CryptoJS.enc.Utf8.parse(aesKey);
|
|
21
|
-
var ciphertext = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Base64.parse(value));
|
|
22
|
-
var encrypted = CryptoJS.DES.decrypt(ciphertext, key, {
|
|
23
|
-
mode: CryptoJS.mode.ECB,
|
|
24
|
-
padding: CryptoJS.pad.Pkcs7
|
|
25
|
-
});
|
|
26
|
-
return encrypted.toString(CryptoJS.enc.Utf8);
|
|
27
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import JSEncrypt from 'jsencrypt';
|
|
2
|
-
export var RSAEncrypt = function RSAEncrypt(value, publicKey, handle) {
|
|
3
|
-
if (typeof handle === 'function') {
|
|
4
|
-
return handle(value, publicKey, JSEncrypt);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
var encryptor = new JSEncrypt();
|
|
8
|
-
encryptor.setPublicKey(publicKey);
|
|
9
|
-
return encryptor.encrypt(value);
|
|
10
|
-
};
|
|
11
|
-
export var RSADecrypt = function RSADecrypt(value, privKey, handle) {
|
|
12
|
-
if (typeof handle === 'function') {
|
|
13
|
-
return handle(value, privKey, JSEncrypt);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var decrypt = new JSEncrypt();
|
|
17
|
-
decrypt.setPrivateKey(privKey);
|
|
18
|
-
return decrypt.decrypt(value);
|
|
19
|
-
};
|
package/es/security/store.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const store: (name: string, options?: any) => any;
|
package/es/security/store.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
var dbStore = {};
|
|
2
|
-
var db;
|
|
3
|
-
var version = 1;
|
|
4
|
-
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
|
5
|
-
export var store = function store(name) {
|
|
6
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
-
|
|
8
|
-
if (!db) {
|
|
9
|
-
db = indexedDB.open('LINGXI', version);
|
|
10
|
-
console.log('db', db);
|
|
11
|
-
|
|
12
|
-
db.onerror = function (error) {
|
|
13
|
-
console.log(error);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
db.onsuccess = function (event) {
|
|
17
|
-
console.log(event);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
db.onupgradeneeded = function (e) {
|
|
21
|
-
// 数据库创建或升级的时候会触发
|
|
22
|
-
console.log('ssss'); // let objectStore
|
|
23
|
-
// if (!e.target.result.objectStoreNames.contains(name)) {
|
|
24
|
-
// objectStore = e.target.result.createObjectStore(name, { keyPath: 'id',autoIncrement: false }) // 创建表
|
|
25
|
-
// }
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
if (dbStore[name]) return dbStore[name];
|
|
29
|
-
return dbStore[name] = {
|
|
30
|
-
add: function add(data) {
|
|
31
|
-
return new Promise(function (resolve, reject) {
|
|
32
|
-
var req = indexedDB.open('LINGXI', version).transaction([name], 'readwrite').objectStore(name) // 仓库对象
|
|
33
|
-
.add(data); // 操作成功
|
|
34
|
-
|
|
35
|
-
req.onsuccess = function () {
|
|
36
|
-
resolve(data);
|
|
37
|
-
}; // 操作失败
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
req.onerror = function () {
|
|
41
|
-
reject(data);
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
put: function put(data) {
|
|
46
|
-
return new Promise(function (resolve, reject) {
|
|
47
|
-
var req = indexedDB.open('LINGXI', version).transaction([name], 'readwrite').objectStore(name).put(data); // 操作成功
|
|
48
|
-
|
|
49
|
-
req.onsuccess = function () {
|
|
50
|
-
resolve(data);
|
|
51
|
-
}; // 操作失败
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
req.onerror = function () {
|
|
55
|
-
reject(data);
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|