xctc-utils 1.6.34 → 1.6.36
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/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +29 -8
- package/dist/iframe/index.d.ts +1 -0
- package/dist/iframe/index.js +12 -2
- package/package.json +1 -1
package/dist/crypto/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import CryptoJS from "crypto-js";
|
|
2
2
|
export declare const cryptojs: typeof CryptoJS;
|
|
3
|
-
export declare function encrypt(word: any, key?: any, iv?: any):
|
|
3
|
+
export declare function encrypt(word: any, key?: any, iv?: any): any;
|
|
4
4
|
export declare function decrypt(word: any, key?: any, iv?: any): any;
|
package/dist/crypto/index.js
CHANGED
|
@@ -15,6 +15,10 @@ function formatVal(val) {
|
|
|
15
15
|
exports.cryptojs = crypto_js_1.default;
|
|
16
16
|
// 加密
|
|
17
17
|
function encrypt(word, key, iv) {
|
|
18
|
+
if (!word) {
|
|
19
|
+
console.error("encrypt函数第一个参数不能为空");
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
18
22
|
if (word instanceof Object) {
|
|
19
23
|
word = JSON.stringify(word);
|
|
20
24
|
}
|
|
@@ -23,25 +27,42 @@ function encrypt(word, key, iv) {
|
|
|
23
27
|
var src = crypto_js_1.default.enc.Utf8.parse(word);
|
|
24
28
|
key = formatVal(key);
|
|
25
29
|
iv = formatVal(iv);
|
|
26
|
-
var
|
|
27
|
-
|
|
30
|
+
var encryptedData = "";
|
|
31
|
+
try {
|
|
32
|
+
var encrypted = crypto_js_1.default.AES.encrypt(src, key, { iv: iv, mode: crypto_js_1.default.mode.CBC, padding: crypto_js_1.default.pad.Pkcs7 });
|
|
33
|
+
encryptedData = encrypted.ciphertext.toString().toUpperCase();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error("encrypt函数加密失败:", error);
|
|
37
|
+
}
|
|
38
|
+
return encryptedData;
|
|
28
39
|
}
|
|
29
40
|
exports.encrypt = encrypt;
|
|
30
41
|
;
|
|
31
42
|
// 解密
|
|
32
43
|
function decrypt(word, key, iv) {
|
|
44
|
+
if (!word) {
|
|
45
|
+
console.error("decrypt函数第一个参数不能为空");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
33
48
|
key = formatVal(key);
|
|
34
49
|
iv = formatVal(iv);
|
|
35
50
|
var encryptedHexStr = crypto_js_1.default.enc.Hex.parse(word);
|
|
36
51
|
var src = crypto_js_1.default.enc.Base64.stringify(encryptedHexStr);
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
var decryptedData = "";
|
|
53
|
+
try {
|
|
54
|
+
var decrypt_1 = crypto_js_1.default.AES.decrypt(src, key, { iv: iv, mode: crypto_js_1.default.mode.CBC, padding: crypto_js_1.default.pad.Pkcs7 });
|
|
55
|
+
var decryptedStr = decrypt_1.toString(crypto_js_1.default.enc.Utf8);
|
|
56
|
+
decryptedData = decryptedStr.toString();
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error("decrypt函数解密失败:", error);
|
|
60
|
+
}
|
|
61
|
+
if ((0, utils_1.isJson)(decryptedData)) {
|
|
62
|
+
return JSON.parse(decryptedData);
|
|
42
63
|
}
|
|
43
64
|
else {
|
|
44
|
-
return
|
|
65
|
+
return decryptedData;
|
|
45
66
|
}
|
|
46
67
|
}
|
|
47
68
|
exports.decrypt = decrypt;
|
package/dist/iframe/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const $iframe: (id: string) => any;
|
|
2
2
|
export declare const initParentDataToIframe: (id: string, keys?: string) => void;
|
|
3
3
|
export declare const updateIframeReceiveData: (cb: any) => void;
|
|
4
|
+
export declare const updateParentReceiveData: (cb: any) => void;
|
|
4
5
|
export declare const sendIframeParentData: (sendData: any, url: string) => void;
|
|
5
6
|
export declare const updateWeiXinShareReady: () => void;
|
|
6
7
|
export declare const sendParentMessage: (data: any, url: string) => void;
|
package/dist/iframe/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendParentMessage = exports.updateWeiXinShareReady = exports.sendIframeParentData = exports.updateIframeReceiveData = exports.initParentDataToIframe = exports.$iframe = void 0;
|
|
3
|
+
exports.sendParentMessage = exports.updateWeiXinShareReady = exports.sendIframeParentData = exports.updateParentReceiveData = exports.updateIframeReceiveData = exports.initParentDataToIframe = exports.$iframe = void 0;
|
|
4
4
|
var is_1 = require("../is");
|
|
5
5
|
var weixin_1 = require("../weixin");
|
|
6
6
|
var utils_1 = require("../utils");
|
|
@@ -53,11 +53,21 @@ var updateIframeReceiveData = function (cb) {
|
|
|
53
53
|
var data = (event === null || event === void 0 ? void 0 : event.data) || {};
|
|
54
54
|
var messageData = (0, utils_1.isJson)(data) || "";
|
|
55
55
|
if (typeof cb === "function" && (messageData === null || messageData === void 0 ? void 0 : messageData.type) == "data") {
|
|
56
|
-
cb(
|
|
56
|
+
cb(messageData === null || messageData === void 0 ? void 0 : messageData.data);
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
59
|
};
|
|
60
60
|
exports.updateIframeReceiveData = updateIframeReceiveData;
|
|
61
|
+
var updateParentReceiveData = function (cb) {
|
|
62
|
+
win.addEventListener('message', function (event) {
|
|
63
|
+
var data = event.data;
|
|
64
|
+
var mainData = (0, utils_1.isJson)(data);
|
|
65
|
+
if (typeof cb === "function" && (mainData === null || mainData === void 0 ? void 0 : mainData.subserver)) {
|
|
66
|
+
cb(mainData);
|
|
67
|
+
}
|
|
68
|
+
}, false);
|
|
69
|
+
};
|
|
70
|
+
exports.updateParentReceiveData = updateParentReceiveData;
|
|
61
71
|
var sendIframeParentData = function (sendData, url) {
|
|
62
72
|
if (!url) {
|
|
63
73
|
console.error("必须传入父页面的地址!");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.36",
|
|
4
4
|
"description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|