@fast-china/utils 2.1.2 → 2.1.4
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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/dist/array/index.d.mts +11 -12
- package/dist/async/index.d.mts +13 -14
- package/dist/async/index.mjs +7 -5
- package/dist/async/index.mjs.map +1 -1
- package/dist/base64/index.d.mts +13 -13
- package/dist/color/index.d.mts +10 -11
- package/dist/crypto/index.d.mts +38 -39
- package/dist/crypto/index.mjs +9 -4
- package/dist/crypto/index.mjs.map +1 -1
- package/dist/date/index.d.mts +23 -24
- package/dist/dom/style.d.mts +5 -6
- package/dist/env/index.d.mts +9 -10
- package/dist/env/index.mjs +17 -10
- package/dist/env/index.mjs.map +1 -1
- package/dist/identity/index.d.mts +5 -6
- package/dist/index.global.min.js +2 -2
- package/dist/index.global.min.js.map +1 -1
- package/dist/internal/runtime.mjs +12 -0
- package/dist/internal/runtime.mjs.map +1 -0
- package/dist/internal/text.d.mts +2 -4
- package/dist/internal/text.mjs +4 -3
- package/dist/internal/text.mjs.map +1 -1
- package/dist/logger/index.d.mts +7 -8
- package/dist/logger/index.mjs +2 -1
- package/dist/logger/index.mjs.map +1 -1
- package/dist/number/index.d.mts +9 -10
- package/dist/number/index.mjs +4 -3
- package/dist/number/index.mjs.map +1 -1
- package/dist/object/index.d.mts +10 -11
- package/dist/storage/index.d.mts +10 -11
- package/dist/storage/index.mjs +4 -3
- package/dist/storage/index.mjs.map +1 -1
- package/dist/string/index.d.mts +18 -19
- package/dist/string/index.mjs +15 -13
- package/dist/string/index.mjs.map +1 -1
- package/dist/vue/emits.d.mts +2 -3
- package/dist/vue/expose.d.mts +1 -2
- package/dist/vue/func.d.mts +2 -3
- package/dist/vue/install.d.mts +6 -7
- package/dist/vue/install.mjs.map +1 -1
- package/dist/vue/props.d.mts +2 -3
- package/dist/vue/render.d.mts +1 -2
- package/dist/vue/slots.d.mts +3 -4
- package/dist/vue/with.d.mts +1 -2
- package/docs/API.md +1 -1
- package/docs/API.zh-CN.md +1 -1
- package/docs/RUNTIME_CONTRACT.md +2 -2
- package/package.json +11 -11
package/dist/crypto/index.d.mts
CHANGED
|
@@ -2,18 +2,18 @@ import { DecodedText } from "../internal/text.mjs";
|
|
|
2
2
|
import "crypto-js/pad-ansix923.js";
|
|
3
3
|
//#region src/crypto/index.d.ts
|
|
4
4
|
/** AES 分组密码模式;与 .NET `CipherMode.CBC` 和 `CipherMode.ECB` 对应。 */
|
|
5
|
-
type AesCipherMode = "CBC" | "ECB";
|
|
5
|
+
export type AesCipherMode = "CBC" | "ECB";
|
|
6
6
|
/** AES 填充模式;与 .NET `PaddingMode` 中可由 CryptoJS 互操作的成员对应。 */
|
|
7
|
-
type AesPaddingMode = "None" | "PKCS7" | "Zeros" | "ANSIX923" | "ISO10126";
|
|
7
|
+
export type AesPaddingMode = "None" | "PKCS7" | "Zeros" | "ANSIX923" | "ISO10126";
|
|
8
8
|
/** Web Crypto 导出的 PEM 公私钥对。 */
|
|
9
|
-
interface PemKeyPair {
|
|
9
|
+
export interface PemKeyPair {
|
|
10
10
|
/** 未加密的 PKCS#8 PEM 私钥,包含标准 `PRIVATE KEY` 头尾和 64 字符换行。 */
|
|
11
11
|
privateKey: string;
|
|
12
12
|
/** SubjectPublicKeyInfo PEM 公钥,包含标准 `PUBLIC KEY` 头尾和 64 字符换行。 */
|
|
13
13
|
publicKey: string;
|
|
14
14
|
}
|
|
15
15
|
/** 本模块支持的 Web Crypto 椭圆曲线。 */
|
|
16
|
-
type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
16
|
+
export type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
17
17
|
/**
|
|
18
18
|
* 生成随机字节。
|
|
19
19
|
*
|
|
@@ -22,7 +22,7 @@ type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
|
22
22
|
* @returns 新建的 `Uint8Array`。
|
|
23
23
|
* @throws 参数非法时抛出 `RangeError`。
|
|
24
24
|
*/
|
|
25
|
-
declare function GenerateRandomBytes(length: number): Uint8Array;
|
|
25
|
+
export declare function GenerateRandomBytes(length: number): Uint8Array;
|
|
26
26
|
/**
|
|
27
27
|
* 以不提前退出的方式比较两个字节数组。
|
|
28
28
|
*
|
|
@@ -32,7 +32,7 @@ declare function GenerateRandomBytes(length: number): Uint8Array;
|
|
|
32
32
|
* @param right - 第二字节序列。
|
|
33
33
|
* @returns 长度和每个字节均相同时返回 `true`。
|
|
34
34
|
*/
|
|
35
|
-
declare function FixedTimeEquals(left: Uint8Array, right: Uint8Array): boolean;
|
|
35
|
+
export declare function FixedTimeEquals(left: Uint8Array, right: Uint8Array): boolean;
|
|
36
36
|
/**
|
|
37
37
|
* 计算 MD5 摘要并返回小写十六进制文本。
|
|
38
38
|
*
|
|
@@ -40,7 +40,7 @@ declare function FixedTimeEquals(left: Uint8Array, right: Uint8Array): boolean;
|
|
|
40
40
|
* @param value - UTF-8 文本。
|
|
41
41
|
* @returns 32 字符小写十六进制摘要。
|
|
42
42
|
*/
|
|
43
|
-
declare function MD5Encrypt(value: string): string;
|
|
43
|
+
export declare function MD5Encrypt(value: string): string;
|
|
44
44
|
/**
|
|
45
45
|
* 计算 SHA-1 摘要并返回大写十六进制文本。
|
|
46
46
|
*
|
|
@@ -48,7 +48,7 @@ declare function MD5Encrypt(value: string): string;
|
|
|
48
48
|
* @param value - UTF-8 文本。
|
|
49
49
|
* @returns 40 字符大写十六进制摘要。
|
|
50
50
|
*/
|
|
51
|
-
declare function SHA1Encrypt(value: string): string;
|
|
51
|
+
export declare function SHA1Encrypt(value: string): string;
|
|
52
52
|
/**
|
|
53
53
|
* 计算 SHA-256 摘要。
|
|
54
54
|
*
|
|
@@ -57,7 +57,7 @@ declare function SHA1Encrypt(value: string): string;
|
|
|
57
57
|
* @returns 32 字节摘要。
|
|
58
58
|
* @throws 缺少 Web Crypto 或 Encoding API 时抛出 `Error`。
|
|
59
59
|
*/
|
|
60
|
-
declare function SHA256Bytes(value: string): Promise<Uint8Array>;
|
|
60
|
+
export declare function SHA256Bytes(value: string): Promise<Uint8Array>;
|
|
61
61
|
/**
|
|
62
62
|
* 计算 SHA-256 并格式化为十六进制。
|
|
63
63
|
*
|
|
@@ -65,35 +65,35 @@ declare function SHA256Bytes(value: string): Promise<Uint8Array>;
|
|
|
65
65
|
* @returns 64 字符大写十六进制文本。
|
|
66
66
|
* @throws 缺少 Web Crypto 或 Encoding API 时抛出 `Error`。
|
|
67
67
|
*/
|
|
68
|
-
declare function SHA256Encrypt(value: string): Promise<string>;
|
|
68
|
+
export declare function SHA256Encrypt(value: string): Promise<string>;
|
|
69
69
|
/**
|
|
70
70
|
* 计算 SHA-384 摘要。
|
|
71
71
|
*
|
|
72
72
|
* @param value - UTF-8 文本或原始字节。
|
|
73
73
|
* @returns 48 字节摘要。
|
|
74
74
|
*/
|
|
75
|
-
declare function SHA384Bytes(value: string): Promise<Uint8Array>;
|
|
75
|
+
export declare function SHA384Bytes(value: string): Promise<Uint8Array>;
|
|
76
76
|
/**
|
|
77
77
|
* 计算 SHA-384 并格式化为十六进制文本。
|
|
78
78
|
*
|
|
79
79
|
* @param value - UTF-8 文本或原始字节。
|
|
80
80
|
* @returns 96 个大写十六进制字符组成的摘要。
|
|
81
81
|
*/
|
|
82
|
-
declare function SHA384Encrypt(value: string): Promise<string>;
|
|
82
|
+
export declare function SHA384Encrypt(value: string): Promise<string>;
|
|
83
83
|
/**
|
|
84
84
|
* 计算 SHA-512 摘要。
|
|
85
85
|
*
|
|
86
86
|
* @param value - UTF-8 文本或原始字节。
|
|
87
87
|
* @returns 64 字节摘要。
|
|
88
88
|
*/
|
|
89
|
-
declare function SHA512Bytes(value: string): Promise<Uint8Array>;
|
|
89
|
+
export declare function SHA512Bytes(value: string): Promise<Uint8Array>;
|
|
90
90
|
/**
|
|
91
91
|
* 计算 SHA-512 并格式化为十六进制文本。
|
|
92
92
|
*
|
|
93
93
|
* @param value - UTF-8 文本或原始字节。
|
|
94
94
|
* @returns 128 个大写十六进制字符组成的摘要。
|
|
95
95
|
*/
|
|
96
|
-
declare function SHA512Encrypt(value: string): Promise<string>;
|
|
96
|
+
export declare function SHA512Encrypt(value: string): Promise<string>;
|
|
97
97
|
/**
|
|
98
98
|
* 使用 HMAC-SHA-256 认证文本,并返回十六进制标签。
|
|
99
99
|
*
|
|
@@ -101,7 +101,7 @@ declare function SHA512Encrypt(value: string): Promise<string>;
|
|
|
101
101
|
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节。
|
|
102
102
|
* @returns 64 个小写十六进制字符组成的认证标签。
|
|
103
103
|
*/
|
|
104
|
-
declare function HMACSHA256Encrypt(value: string, key: string): Promise<string>;
|
|
104
|
+
export declare function HMACSHA256Encrypt(value: string, key: string): Promise<string>;
|
|
105
105
|
/**
|
|
106
106
|
* 使用 HMAC-SHA-384 认证文本或字节,并返回十六进制标签。
|
|
107
107
|
*
|
|
@@ -109,7 +109,7 @@ declare function HMACSHA256Encrypt(value: string, key: string): Promise<string>;
|
|
|
109
109
|
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节。
|
|
110
110
|
* @returns 96 个小写十六进制字符组成的认证标签。
|
|
111
111
|
*/
|
|
112
|
-
declare function HMACSHA384Encrypt(value: string, key: string): Promise<string>;
|
|
112
|
+
export declare function HMACSHA384Encrypt(value: string, key: string): Promise<string>;
|
|
113
113
|
/**
|
|
114
114
|
* 使用 HMAC-SHA-512 认证文本或字节,并返回十六进制标签。
|
|
115
115
|
*
|
|
@@ -117,7 +117,7 @@ declare function HMACSHA384Encrypt(value: string, key: string): Promise<string>;
|
|
|
117
117
|
* @param key - 非空的 UTF-8 文本密钥或原始密钥字节。
|
|
118
118
|
* @returns 128 个小写十六进制字符组成的认证标签。
|
|
119
119
|
*/
|
|
120
|
-
declare function HMACSHA512Encrypt(value: string, key: string): Promise<string>;
|
|
120
|
+
export declare function HMACSHA512Encrypt(value: string, key: string): Promise<string>;
|
|
121
121
|
/**
|
|
122
122
|
* 使用 PBKDF2-HMAC-SHA-256 从密码派生密钥。
|
|
123
123
|
*
|
|
@@ -128,7 +128,7 @@ declare function HMACSHA512Encrypt(value: string, key: string): Promise<string>;
|
|
|
128
128
|
* @returns 指定长度的派生密钥。
|
|
129
129
|
* @throws 参数超过协议边界时抛出 `TypeError` 或 `RangeError`。
|
|
130
130
|
*/
|
|
131
|
-
declare function PBKDF2SHA256(password: string, salt: Uint8Array, iterations?: number, outputLength?: number): Promise<Uint8Array>;
|
|
131
|
+
export declare function PBKDF2SHA256(password: string, salt: Uint8Array, iterations?: number, outputLength?: number): Promise<Uint8Array>;
|
|
132
132
|
/**
|
|
133
133
|
* 生成可持久化的随机盐 PBKDF2-HMAC-SHA-256 密码哈希。
|
|
134
134
|
*
|
|
@@ -136,7 +136,7 @@ declare function PBKDF2SHA256(password: string, salt: Uint8Array, iterations?: n
|
|
|
136
136
|
* @param iterations - 迭代次数,范围为 100,000 至 5,000,000。
|
|
137
137
|
* @returns 包含版本、迭代次数、16 字节随机盐和 32 字节派生密钥的自描述字符串。
|
|
138
138
|
*/
|
|
139
|
-
declare function HashPasswordPBKDF2SHA256(password: string, iterations?: number): Promise<string>;
|
|
139
|
+
export declare function HashPasswordPBKDF2SHA256(password: string, iterations?: number): Promise<string>;
|
|
140
140
|
/**
|
|
141
141
|
* 验证 {@link HashPasswordPBKDF2SHA256} 生成的密码哈希。
|
|
142
142
|
*
|
|
@@ -144,7 +144,7 @@ declare function HashPasswordPBKDF2SHA256(password: string, iterations?: number)
|
|
|
144
144
|
* @param passwordHash - 自描述的 PBKDF2-HMAC-SHA-256 密码哈希。
|
|
145
145
|
* @returns 格式有效且密码匹配时返回 `true`;格式无效或密码错误时返回 `false`。
|
|
146
146
|
*/
|
|
147
|
-
declare function VerifyPasswordPBKDF2SHA256(password: string, passwordHash: string): Promise<boolean>;
|
|
147
|
+
export declare function VerifyPasswordPBKDF2SHA256(password: string, passwordHash: string): Promise<boolean>;
|
|
148
148
|
/**
|
|
149
149
|
* 使用 RFC 5869 HKDF-SHA-256 派生上下文隔离的密钥材料。
|
|
150
150
|
*
|
|
@@ -154,7 +154,7 @@ declare function VerifyPasswordPBKDF2SHA256(password: string, passwordHash: stri
|
|
|
154
154
|
* @param outputLength - 输出长度,范围为 1 至 8,160 字节。
|
|
155
155
|
* @returns 与 `salt` 和 `info` 绑定的派生密钥。
|
|
156
156
|
*/
|
|
157
|
-
declare function HKDFSHA256(inputKeyMaterial: Uint8Array, salt?: Uint8Array, info?: Uint8Array, outputLength?: number): Promise<Uint8Array>;
|
|
157
|
+
export declare function HKDFSHA256(inputKeyMaterial: Uint8Array, salt?: Uint8Array, info?: Uint8Array, outputLength?: number): Promise<Uint8Array>;
|
|
158
158
|
/**
|
|
159
159
|
* 使用 AES-256 对 UTF-8 文本进行分组加密。
|
|
160
160
|
*
|
|
@@ -168,7 +168,7 @@ declare function HKDFSHA256(inputKeyMaterial: Uint8Array, salt?: Uint8Array, inf
|
|
|
168
168
|
* @returns Base64 密文;输入、密钥或 IV 为空白时返回 `null`。
|
|
169
169
|
* @throws 模式或填充不受支持时抛出 `RangeError`。
|
|
170
170
|
*/
|
|
171
|
-
declare function AESEncrypt(dataStr: string, key: string, vector: string, cipherMode?: AesCipherMode, paddingMode?: AesPaddingMode): string | null;
|
|
171
|
+
export declare function AESEncrypt(dataStr: string, key: string, vector: string, cipherMode?: AesCipherMode, paddingMode?: AesPaddingMode): string | null;
|
|
172
172
|
/**
|
|
173
173
|
* 使用 AES-256 解密 Base64 分组密文。
|
|
174
174
|
*
|
|
@@ -181,7 +181,7 @@ declare function AESEncrypt(dataStr: string, key: string, vector: string, cipher
|
|
|
181
181
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串;输入、密钥或 IV 为空白时返回 `null`。
|
|
182
182
|
* @throws 模式、填充、Base64、密钥或密文无效时抛出错误。
|
|
183
183
|
*/
|
|
184
|
-
declare function AESDecrypt(dataStr: string, key: string, vector: string, cipherMode?: AesCipherMode, paddingMode?: AesPaddingMode): DecodedText | null;
|
|
184
|
+
export declare function AESDecrypt(dataStr: string, key: string, vector: string, cipherMode?: AesCipherMode, paddingMode?: AesPaddingMode): DecodedText | null;
|
|
185
185
|
/**
|
|
186
186
|
* 使用 SHA-256 归一化文本密钥,再以 AES-256-GCM 认证加密 UTF-8 文本。
|
|
187
187
|
*
|
|
@@ -191,7 +191,7 @@ declare function AESDecrypt(dataStr: string, key: string, vector: string, cipher
|
|
|
191
191
|
* @returns Base64 编码的 v1 AES-GCM 认证载荷。
|
|
192
192
|
* @throws 密钥为空或运行时缺少 Web Crypto 时抛出错误。
|
|
193
193
|
*/
|
|
194
|
-
declare function AESEncryptAuthenticated(plaintext: string, key: string): Promise<string>;
|
|
194
|
+
export declare function AESEncryptAuthenticated(plaintext: string, key: string): Promise<string>;
|
|
195
195
|
/**
|
|
196
196
|
* 解密并认证 .NET `AESEncryptAuthenticated` 或 {@link AESEncryptAuthenticated} 生成的载荷。
|
|
197
197
|
*
|
|
@@ -200,7 +200,7 @@ declare function AESEncryptAuthenticated(plaintext: string, key: string): Promis
|
|
|
200
200
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串。
|
|
201
201
|
* @throws 载荷格式无效、密钥错误或认证失败时抛出错误。
|
|
202
202
|
*/
|
|
203
|
-
declare function AESDecryptAuthenticated(payload: string, key: string): Promise<DecodedText>;
|
|
203
|
+
export declare function AESDecryptAuthenticated(payload: string, key: string): Promise<DecodedText>;
|
|
204
204
|
/**
|
|
205
205
|
* 使用 PBKDF2-HMAC-SHA-256 派生密钥,再以 AES-256-GCM 认证加密 UTF-8 文本。
|
|
206
206
|
*
|
|
@@ -213,7 +213,7 @@ declare function AESDecryptAuthenticated(payload: string, key: string): Promise<
|
|
|
213
213
|
* @throws 口令非法时抛出 `TypeError` 或 `RangeError`;明文过大时抛出 `RangeError`;
|
|
214
214
|
* 运行时缺少 Web Crypto 或 Encoding API 时抛出 `Error`。
|
|
215
215
|
*/
|
|
216
|
-
declare function AESEncryptWithPassword(plaintext: string, password: string, iterations?: number): Promise<string>;
|
|
216
|
+
export declare function AESEncryptWithPassword(plaintext: string, password: string, iterations?: number): Promise<string>;
|
|
217
217
|
/**
|
|
218
218
|
* 解密 {@link AESEncryptWithPassword} 生成的 v1 认证载荷。
|
|
219
219
|
*
|
|
@@ -223,7 +223,7 @@ declare function AESEncryptWithPassword(plaintext: string, password: string, ite
|
|
|
223
223
|
* @throws 格式或字段非法时抛出 `TypeError`,载荷过大时抛出 `RangeError`,认证或密码
|
|
224
224
|
* 失败及缺少平台能力时抛出 `Error`。
|
|
225
225
|
*/
|
|
226
|
-
declare function AESDecryptWithPassword(payload: string, password: string): Promise<DecodedText>;
|
|
226
|
+
export declare function AESDecryptWithPassword(payload: string, password: string): Promise<DecodedText>;
|
|
227
227
|
/**
|
|
228
228
|
* 生成可供 RSA-OAEP/SHA-256 与 RSA-PSS/SHA-256 共用的 PEM 密钥对。
|
|
229
229
|
*
|
|
@@ -231,7 +231,7 @@ declare function AESDecryptWithPassword(payload: string, password: string): Prom
|
|
|
231
231
|
* @returns 未加密 PKCS#8 私钥和 SubjectPublicKeyInfo 公钥组成的 PEM 密钥对。
|
|
232
232
|
* @throws 模数小于 2,048 或不是 256 的倍数时抛出 `RangeError`。
|
|
233
233
|
*/
|
|
234
|
-
declare function GenerateRSAKeyPair(modulusLength?: number): Promise<PemKeyPair>;
|
|
234
|
+
export declare function GenerateRSAKeyPair(modulusLength?: number): Promise<PemKeyPair>;
|
|
235
235
|
/**
|
|
236
236
|
* 使用 RSA-OAEP/SHA-256 公钥加密 UTF-8 文本。
|
|
237
237
|
*
|
|
@@ -240,7 +240,7 @@ declare function GenerateRSAKeyPair(modulusLength?: number): Promise<PemKeyPair>
|
|
|
240
240
|
* @returns Base64 编码的 RSA 密文。
|
|
241
241
|
* @throws 公钥格式无效或明文超过 RSA-OAEP 容量时抛出错误。
|
|
242
242
|
*/
|
|
243
|
-
declare function RSAEncryptOAEP(plaintext: string, publicKeyPem: string): Promise<string>;
|
|
243
|
+
export declare function RSAEncryptOAEP(plaintext: string, publicKeyPem: string): Promise<string>;
|
|
244
244
|
/**
|
|
245
245
|
* 使用 RSA-OAEP/SHA-256 私钥解密 Base64 密文。
|
|
246
246
|
*
|
|
@@ -249,7 +249,7 @@ declare function RSAEncryptOAEP(plaintext: string, publicKeyPem: string): Promis
|
|
|
249
249
|
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 UTF-8 字符串。
|
|
250
250
|
* @throws 私钥、Base64 或密文无效时抛出错误。
|
|
251
251
|
*/
|
|
252
|
-
declare function RSADecryptOAEP(ciphertext: string, privateKeyPem: string): Promise<DecodedText>;
|
|
252
|
+
export declare function RSADecryptOAEP(ciphertext: string, privateKeyPem: string): Promise<DecodedText>;
|
|
253
253
|
/**
|
|
254
254
|
* 使用 RSA-PSS/SHA-256 私钥签名文本或字节。
|
|
255
255
|
*
|
|
@@ -258,7 +258,7 @@ declare function RSADecryptOAEP(ciphertext: string, privateKeyPem: string): Prom
|
|
|
258
258
|
* @returns Base64 编码的 RSA-PSS 签名;盐长度固定为 32 字节。
|
|
259
259
|
* @throws 私钥格式无效或签名失败时抛出错误。
|
|
260
260
|
*/
|
|
261
|
-
declare function RSASignPSS(value: string, privateKeyPem: string): Promise<string>;
|
|
261
|
+
export declare function RSASignPSS(value: string, privateKeyPem: string): Promise<string>;
|
|
262
262
|
/**
|
|
263
263
|
* 使用 RSA-PSS/SHA-256 公钥验证 Base64 签名。
|
|
264
264
|
*
|
|
@@ -268,14 +268,14 @@ declare function RSASignPSS(value: string, privateKeyPem: string): Promise<strin
|
|
|
268
268
|
* @returns 签名与内容、公钥匹配时返回 `true`。
|
|
269
269
|
* @throws 公钥或 Base64 格式无效时抛出错误。
|
|
270
270
|
*/
|
|
271
|
-
declare function RSAVerifyPSS(value: string, signature: string, publicKeyPem: string): Promise<boolean>;
|
|
271
|
+
export declare function RSAVerifyPSS(value: string, signature: string, publicKeyPem: string): Promise<boolean>;
|
|
272
272
|
/**
|
|
273
273
|
* 生成 ECDSA PEM 签名密钥对。
|
|
274
274
|
*
|
|
275
275
|
* @param namedCurve - NIST 曲线:P-256、P-384 或 P-521。
|
|
276
276
|
* @returns 未加密 PKCS#8 私钥和 SubjectPublicKeyInfo 公钥组成的 PEM 密钥对。
|
|
277
277
|
*/
|
|
278
|
-
declare function GenerateECDSAKeyPair(namedCurve?: EcNamedCurve): Promise<PemKeyPair>;
|
|
278
|
+
export declare function GenerateECDSAKeyPair(namedCurve?: EcNamedCurve): Promise<PemKeyPair>;
|
|
279
279
|
/**
|
|
280
280
|
* 使用 ECDSA 私钥签名文本或字节。
|
|
281
281
|
*
|
|
@@ -285,7 +285,7 @@ declare function GenerateECDSAKeyPair(namedCurve?: EcNamedCurve): Promise<PemKey
|
|
|
285
285
|
* @param namedCurve - 私钥使用的 NIST 曲线。
|
|
286
286
|
* @returns Base64 编码的 IEEE P1363 ECDSA 签名。
|
|
287
287
|
*/
|
|
288
|
-
declare function ECDSASign(value: string, privateKeyPem: string, namedCurve?: EcNamedCurve): Promise<string>;
|
|
288
|
+
export declare function ECDSASign(value: string, privateKeyPem: string, namedCurve?: EcNamedCurve): Promise<string>;
|
|
289
289
|
/**
|
|
290
290
|
* 使用 ECDSA 公钥验证 Base64 签名。
|
|
291
291
|
*
|
|
@@ -295,14 +295,14 @@ declare function ECDSASign(value: string, privateKeyPem: string, namedCurve?: Ec
|
|
|
295
295
|
* @param namedCurve - 公钥使用的 NIST 曲线。
|
|
296
296
|
* @returns 签名与内容、公钥和曲线匹配时返回 `true`。
|
|
297
297
|
*/
|
|
298
|
-
declare function ECDSAVerify(value: string, signature: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<boolean>;
|
|
298
|
+
export declare function ECDSAVerify(value: string, signature: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<boolean>;
|
|
299
299
|
/**
|
|
300
300
|
* 生成 ECDH PEM 密钥协商密钥对。
|
|
301
301
|
*
|
|
302
302
|
* @param namedCurve - NIST 曲线:P-256、P-384 或 P-521。
|
|
303
303
|
* @returns 未加密 PKCS#8 私钥和 SubjectPublicKeyInfo 公钥组成的 PEM 密钥对。
|
|
304
304
|
*/
|
|
305
|
-
declare function GenerateECDHKeyPair(namedCurve?: EcNamedCurve): Promise<PemKeyPair>;
|
|
305
|
+
export declare function GenerateECDHKeyPair(namedCurve?: EcNamedCurve): Promise<PemKeyPair>;
|
|
306
306
|
/**
|
|
307
307
|
* 使用本方 ECDH 私钥与对方 ECDH 公钥派生共享秘密。
|
|
308
308
|
*
|
|
@@ -312,7 +312,7 @@ declare function GenerateECDHKeyPair(namedCurve?: EcNamedCurve): Promise<PemKeyP
|
|
|
312
312
|
* @param namedCurve - 双方密钥使用的 NIST 曲线。
|
|
313
313
|
* @returns 曲线字段长度的原始 ECDH 共享秘密。
|
|
314
314
|
*/
|
|
315
|
-
declare function DeriveECDHSecret(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
315
|
+
export declare function DeriveECDHSecret(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
316
316
|
/**
|
|
317
317
|
* 使用 ECDH 后以 SHA-256 派生共享密钥。
|
|
318
318
|
*
|
|
@@ -322,7 +322,6 @@ declare function DeriveECDHSecret(privateKeyPem: string, publicKeyPem: string, n
|
|
|
322
322
|
* @param namedCurve - 双方密钥使用的 NIST 曲线。
|
|
323
323
|
* @returns 32 字节共享密钥。
|
|
324
324
|
*/
|
|
325
|
-
declare function DeriveECDHKeySHA256(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
325
|
+
export declare function DeriveECDHKeySHA256(privateKeyPem: string, publicKeyPem: string, namedCurve?: EcNamedCurve): Promise<Uint8Array>;
|
|
326
326
|
//#endregion
|
|
327
|
-
export { AESDecrypt, AESDecryptAuthenticated, AESDecryptWithPassword, AESEncrypt, AESEncryptAuthenticated, AESEncryptWithPassword, AesCipherMode, AesPaddingMode, DeriveECDHKeySHA256, DeriveECDHSecret, ECDSASign, ECDSAVerify, EcNamedCurve, FixedTimeEquals, GenerateECDHKeyPair, GenerateECDSAKeyPair, GenerateRSAKeyPair, GenerateRandomBytes, HKDFSHA256, HMACSHA256Encrypt, HMACSHA384Encrypt, HMACSHA512Encrypt, HashPasswordPBKDF2SHA256, MD5Encrypt, PBKDF2SHA256, PemKeyPair, RSADecryptOAEP, RSAEncryptOAEP, RSASignPSS, RSAVerifyPSS, SHA1Encrypt, SHA256Bytes, SHA256Encrypt, SHA384Bytes, SHA384Encrypt, SHA512Bytes, SHA512Encrypt, VerifyPasswordPBKDF2SHA256 };
|
|
328
327
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/crypto/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createDecodedText, encodeUtf8, getTextDecoder } from "../internal/text.mjs";
|
|
2
|
+
import { runtimeGlobals } from "../internal/runtime.mjs";
|
|
2
3
|
import { decodeBase64Bytes, decodeBase64UrlBytes, encodeBase64Bytes, encodeBase64UrlBytes } from "../base64/index.mjs";
|
|
3
4
|
import AES from "crypto-js/aes.js";
|
|
4
5
|
import CryptoCore from "crypto-js/core.js";
|
|
@@ -31,6 +32,10 @@ const encryptedPayloadPrefix = "FAST-AES-256-GCM-V1";
|
|
|
31
32
|
const passwordHashPrefix = "FAST-PBKDF2-SHA256-V1";
|
|
32
33
|
/** 直接 AES-GCM 密钥加密载荷的协议版本。 */
|
|
33
34
|
const authenticatedAesPayloadVersion = 1;
|
|
35
|
+
/** 校验 JavaScript 调用方传入的 AES 分组模式。 */
|
|
36
|
+
const assertAesCipherMode = (value) => {
|
|
37
|
+
if (value !== "CBC" && value !== "ECB") throw new RangeError("`cipherMode` 必须是 `CBC` 或 `ECB`。");
|
|
38
|
+
};
|
|
34
39
|
/**
|
|
35
40
|
* 获取本模块非随机 API 所需的完整 Web Crypto 能力。
|
|
36
41
|
*
|
|
@@ -38,7 +43,7 @@ const authenticatedAesPayloadVersion = 1;
|
|
|
38
43
|
* @throws `Error` 当任一必要 SubtleCrypto 方法缺失。
|
|
39
44
|
*/
|
|
40
45
|
const requireWebCrypto = () => {
|
|
41
|
-
const crypto =
|
|
46
|
+
const crypto = runtimeGlobals.crypto;
|
|
42
47
|
const subtle = crypto?.subtle;
|
|
43
48
|
if (typeof subtle?.decrypt !== "function" || typeof subtle.deriveBits !== "function" || typeof subtle.deriveKey !== "function" || typeof subtle.digest !== "function" || typeof subtle.encrypt !== "function" || typeof subtle.exportKey !== "function" || typeof subtle.generateKey !== "function" || typeof subtle.importKey !== "function" || typeof subtle.sign !== "function" || typeof subtle.verify !== "function") throw new Error("当前运行环境不支持 Web Crypto SubtleCrypto。");
|
|
44
49
|
return crypto;
|
|
@@ -173,7 +178,7 @@ const computeHmacBytes = async (value, key, hash) => {
|
|
|
173
178
|
function GenerateRandomBytes(length) {
|
|
174
179
|
if (!Number.isSafeInteger(length) || length < 0 || length > 65536) throw new RangeError("`length` 必须是 0 到 65,536 之间的安全整数。");
|
|
175
180
|
const bytes = new Uint8Array(length);
|
|
176
|
-
const crypto =
|
|
181
|
+
const crypto = runtimeGlobals.crypto;
|
|
177
182
|
if (typeof crypto?.getRandomValues === "function") return crypto.getRandomValues(bytes);
|
|
178
183
|
for (let index = 0; index < bytes.length; index += 1) bytes[index] = Math.floor(Math.random() * 256);
|
|
179
184
|
return bytes;
|
|
@@ -400,7 +405,7 @@ async function HKDFSHA256(inputKeyMaterial, salt = /* @__PURE__ */ new Uint8Arra
|
|
|
400
405
|
*/
|
|
401
406
|
function AESEncrypt(dataStr, key, vector, cipherMode = "CBC", paddingMode = "PKCS7") {
|
|
402
407
|
if (dataStr.trim().length === 0 || key.trim().length === 0 || vector.trim().length === 0) return null;
|
|
403
|
-
|
|
408
|
+
assertAesCipherMode(cipherMode);
|
|
404
409
|
let padding = Pkcs7;
|
|
405
410
|
switch (paddingMode) {
|
|
406
411
|
case "None":
|
|
@@ -444,7 +449,7 @@ function AESEncrypt(dataStr, key, vector, cipherMode = "CBC", paddingMode = "PKC
|
|
|
444
449
|
*/
|
|
445
450
|
function AESDecrypt(dataStr, key, vector, cipherMode = "CBC", paddingMode = "PKCS7") {
|
|
446
451
|
if (dataStr.trim().length === 0 || key.trim().length === 0 || vector.trim().length === 0) return null;
|
|
447
|
-
|
|
452
|
+
assertAesCipherMode(cipherMode);
|
|
448
453
|
let padding = Pkcs7;
|
|
449
454
|
switch (paddingMode) {
|
|
450
455
|
case "None":
|