@fastcar/core 0.2.44 → 0.2.45
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/package.json +1 -1
- package/src/utils/CryptoUtil.ts +13 -8
- package/target/utils/CryptoUtil.js +10 -8
- package/utils.d.ts +2 -0
package/package.json
CHANGED
package/src/utils/CryptoUtil.ts
CHANGED
|
@@ -74,10 +74,7 @@ export default class CryptoUtil {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
static sha256Encode(text: string, serect: string = crypto.randomBytes(32).toString("hex"), encoding: BinaryToTextEncoding = "base64"): { salt: string; msg: string } {
|
|
77
|
-
let msg = crypto
|
|
78
|
-
.createHmac("sha256", serect)
|
|
79
|
-
.update(text)
|
|
80
|
-
.digest(encoding);
|
|
77
|
+
let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
|
|
81
78
|
|
|
82
79
|
return {
|
|
83
80
|
salt: serect,
|
|
@@ -86,10 +83,7 @@ export default class CryptoUtil {
|
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
static sha256EncodeContent(str: string, encoding: BinaryToTextEncoding = "base64"): string {
|
|
89
|
-
let msg = crypto
|
|
90
|
-
.createHash("sha256")
|
|
91
|
-
.update(str)
|
|
92
|
-
.digest(encoding);
|
|
86
|
+
let msg = crypto.createHash("sha256").update(str).digest(encoding);
|
|
93
87
|
|
|
94
88
|
return msg;
|
|
95
89
|
}
|
|
@@ -103,4 +97,15 @@ export default class CryptoUtil {
|
|
|
103
97
|
static getHashStr(num: number = 16): string {
|
|
104
98
|
return crypto.randomBytes(num).toString("hex");
|
|
105
99
|
}
|
|
100
|
+
|
|
101
|
+
//根据给定的字符串返回hash值按照追加的原则
|
|
102
|
+
static getHashStrByLength(serect: string, num: number): string {
|
|
103
|
+
let list = crypto.createHash("md5").update(serect).digest().toString("hex");
|
|
104
|
+
|
|
105
|
+
while (list.length < num) {
|
|
106
|
+
list = list.repeat(num - list.length);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return list.substring(0, num);
|
|
110
|
+
}
|
|
106
111
|
}
|
|
@@ -57,20 +57,14 @@ class CryptoUtil {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
static sha256Encode(text, serect = crypto.randomBytes(32).toString("hex"), encoding = "base64") {
|
|
60
|
-
let msg = crypto
|
|
61
|
-
.createHmac("sha256", serect)
|
|
62
|
-
.update(text)
|
|
63
|
-
.digest(encoding);
|
|
60
|
+
let msg = crypto.createHmac("sha256", serect).update(text).digest(encoding);
|
|
64
61
|
return {
|
|
65
62
|
salt: serect,
|
|
66
63
|
msg: msg,
|
|
67
64
|
};
|
|
68
65
|
}
|
|
69
66
|
static sha256EncodeContent(str, encoding = "base64") {
|
|
70
|
-
let msg = crypto
|
|
71
|
-
.createHash("sha256")
|
|
72
|
-
.update(str)
|
|
73
|
-
.digest(encoding);
|
|
67
|
+
let msg = crypto.createHash("sha256").update(str).digest(encoding);
|
|
74
68
|
return msg;
|
|
75
69
|
}
|
|
76
70
|
static sha256Very(msg, serect, encodeMsg, encoding = "base64") {
|
|
@@ -80,5 +74,13 @@ class CryptoUtil {
|
|
|
80
74
|
static getHashStr(num = 16) {
|
|
81
75
|
return crypto.randomBytes(num).toString("hex");
|
|
82
76
|
}
|
|
77
|
+
//根据给定的字符串返回hash值按照追加的原则
|
|
78
|
+
static getHashStrByLength(serect, num) {
|
|
79
|
+
let list = crypto.createHash("md5").update(serect).digest().toString("hex");
|
|
80
|
+
while (list.length < num) {
|
|
81
|
+
list = list.repeat(num - list.length);
|
|
82
|
+
}
|
|
83
|
+
return list.substring(0, num);
|
|
84
|
+
}
|
|
83
85
|
}
|
|
84
86
|
exports.default = CryptoUtil;
|
package/utils.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export class CryptoUtil {
|
|
|
57
57
|
static sha256Very(msg: string, serect: string, encodeMsg: string, encoding?: BinaryToTextEncoding): boolean;
|
|
58
58
|
|
|
59
59
|
static getHashStr(num?: number): string;
|
|
60
|
+
|
|
61
|
+
static getHashStrByLength(serect: string, num: number): string;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export class FileUtil {
|