ms-vite-plugin 1.1.2 → 1.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/dist/build.js +6 -0
- package/dist/cli.js +91 -1
- package/dist/mcp/device-config.d.ts +55 -0
- package/dist/mcp/device-config.js +183 -0
- package/dist/mcp/docs-service.d.ts +65 -0
- package/dist/mcp/docs-service.js +168 -0
- package/dist/mcp/project.d.ts +16 -0
- package/dist/mcp/project.js +74 -0
- package/dist/mcp/tools.d.ts +18 -0
- package/dist/mcp/tools.js +825 -0
- package/dist/mcp/types.d.ts +32 -0
- package/dist/mcp/types.js +11 -0
- package/dist/mcp-server.d.ts +2 -0
- package/dist/mcp-server.js +86 -0
- package/dist/project.d.ts +89 -0
- package/dist/project.js +306 -0
- package/dist/version.d.ts +12 -0
- package/dist/version.js +63 -0
- package/docs/api/action.md +922 -0
- package/docs/api/appleocr.md +229 -0
- package/docs/api/config.md +122 -0
- package/docs/api/cryptoUtils.md +232 -0
- package/docs/api/device.md +374 -0
- package/docs/api/file.md +516 -0
- package/docs/api/global.md +617 -0
- package/docs/api/hid.md +1032 -0
- package/docs/api/hotUpdate.md +166 -0
- package/docs/api/http.md +548 -0
- package/docs/api/image.md +907 -0
- package/docs/api/ime.md +290 -0
- package/docs/api/logger.md +324 -0
- package/docs/api/media.md +248 -0
- package/docs/api/mysql.md +441 -0
- package/docs/api/netCard.md +200 -0
- package/docs/api/node.md +353 -0
- package/docs/api/paddleocr.md +246 -0
- package/docs/api/pip.md +242 -0
- package/docs/api/system.md +572 -0
- package/docs/api/thread.md +269 -0
- package/docs/api/tomatoocr.md +425 -0
- package/docs/api/tts.md +334 -0
- package/docs/api/ui.md +947 -0
- package/docs/api/utils.md +265 -0
- package/docs/api/yolo.md +310 -0
- package/docs/apicn/action.md +919 -0
- package/docs/apicn/appleocr.md +233 -0
- package/docs/apicn/config.md +120 -0
- package/docs/apicn/device.md +385 -0
- package/docs/apicn/file.md +511 -0
- package/docs/apicn/global.md +613 -0
- package/docs/apicn/hid.md +1033 -0
- package/docs/apicn/hotUpdate.md +170 -0
- package/docs/apicn/http.md +672 -0
- package/docs/apicn/image.md +924 -0
- package/docs/apicn/ime.md +290 -0
- package/docs/apicn/logger.md +332 -0
- package/docs/apicn/media.md +252 -0
- package/docs/apicn/mysql.md +445 -0
- package/docs/apicn/netCard.md +200 -0
- package/docs/apicn/node.md +362 -0
- package/docs/apicn/paddleocr.md +255 -0
- package/docs/apicn/pip.md +242 -0
- package/docs/apicn/system.md +575 -0
- package/docs/apicn/thread.md +269 -0
- package/docs/apicn/tts.md +338 -0
- package/docs/apicn/ui.md +933 -0
- package/docs/apicn/utils.md +265 -0
- package/docs/apicn/yolo.md +314 -0
- package/docs/apipython/action.md +901 -0
- package/docs/apipython/appleocr.md +226 -0
- package/docs/apipython/config.md +126 -0
- package/docs/apipython/cryptoUtils.md +246 -0
- package/docs/apipython/device.md +365 -0
- package/docs/apipython/file.md +476 -0
- package/docs/apipython/g.md +154 -0
- package/docs/apipython/hid.md +1059 -0
- package/docs/apipython/hotUpdate.md +154 -0
- package/docs/apipython/image.md +938 -0
- package/docs/apipython/ime.md +306 -0
- package/docs/apipython/logger.md +330 -0
- package/docs/apipython/media.md +221 -0
- package/docs/apipython/mysql.md +432 -0
- package/docs/apipython/netCard.md +219 -0
- package/docs/apipython/node.md +331 -0
- package/docs/apipython/overview.md +66 -0
- package/docs/apipython/paddleocr.md +211 -0
- package/docs/apipython/pip.md +231 -0
- package/docs/apipython/system.md +458 -0
- package/docs/apipython/tomatoocr.md +444 -0
- package/docs/apipython/tts.md +331 -0
- package/docs/apipython/ui.md +949 -0
- package/docs/apipython/utils.md +284 -0
- package/docs/apipython/yolo.md +281 -0
- package/package.json +8 -4
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# AppleOCR 模块
|
|
2
|
+
|
|
3
|
+
AppleOCR 模块基于 Apple Vision 框架,提供原生的光学字符识别(OCR)功能。该模块利用 iOS 系统内置的机器学习能力,无需额外模型文件,具有高效、准确的特点。
|
|
4
|
+
|
|
5
|
+
<span style="color: red;">此模块仅支持 iOS 系统。</span>
|
|
6
|
+
|
|
7
|
+
## 核心特性
|
|
8
|
+
|
|
9
|
+
### 🚀 性能优势
|
|
10
|
+
|
|
11
|
+
- **原生支持**: 基于 Apple Vision 框架,无需额外模型文件
|
|
12
|
+
- **高性能**: 利用 iOS 系统优化,识别速度快
|
|
13
|
+
- **低资源占用**: 无需加载大型模型文件
|
|
14
|
+
|
|
15
|
+
### 🌍 多语言支持
|
|
16
|
+
|
|
17
|
+
- **默认语言**: 中文和英文(["zh-Hans", "en-US"])
|
|
18
|
+
- **支持语言**: ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]
|
|
19
|
+
|
|
20
|
+
### 📱 多种输入源
|
|
21
|
+
|
|
22
|
+
- **屏幕截图**: 直接识别当前屏幕内容
|
|
23
|
+
- **图片文件**: 支持本地图片文件路径
|
|
24
|
+
- **图片 ID**: 通过 image 模块获取的图片 ID
|
|
25
|
+
- **区域识别**: 支持指定区域的精确文字识别
|
|
26
|
+
|
|
27
|
+
## 数据类型
|
|
28
|
+
|
|
29
|
+
### OCRResult
|
|
30
|
+
|
|
31
|
+
识别结果对象,包含以下属性:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
interface OCRResult {
|
|
35
|
+
text: string; // 识别的文本内容
|
|
36
|
+
confidence: number; // 识别置信度 (0-1)
|
|
37
|
+
x: number; // 文本区域左上角 x 坐标
|
|
38
|
+
y: number; // 文本区域左上角 y 坐标
|
|
39
|
+
width: number; // 文本区域宽度
|
|
40
|
+
height: number; // 文本区域高度
|
|
41
|
+
ex: number; // 文本区域右下角 x 坐标
|
|
42
|
+
ey: number; // 文本区域右下角 y 坐标
|
|
43
|
+
centerX: number; // 文本区域中心点 x 坐标
|
|
44
|
+
centerY: number; // 文本区域中心点 y 坐标
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**字段说明:**
|
|
49
|
+
| 参数名 | 类型 | 描述 |
|
|
50
|
+
| ------------- | ----------- | ---------------------- |
|
|
51
|
+
| `text` | string | 识别的文本内容 |
|
|
52
|
+
| `confidence` | number | 识别置信度 (0-1),值越高表示识别越准确 |
|
|
53
|
+
| `x`, `y` | number | 文本区域左上角坐标 |
|
|
54
|
+
| `width`, `height` | number | 文本区域宽度和高度 |
|
|
55
|
+
| `ex`, `ey` | number | 文本区域右下角坐标 |
|
|
56
|
+
| `centerX`, `centerY` | number | 文本区域中心点坐标 |
|
|
57
|
+
|
|
58
|
+
## API 参考
|
|
59
|
+
|
|
60
|
+
### 文字识别
|
|
61
|
+
|
|
62
|
+
#### recognize
|
|
63
|
+
|
|
64
|
+
执行通用 OCR 文字识别,支持多种输入源和指定识别区域。
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
function recognize(
|
|
68
|
+
input: string,
|
|
69
|
+
x?: number,
|
|
70
|
+
y?: number,
|
|
71
|
+
ex?: number,
|
|
72
|
+
ey?: number,
|
|
73
|
+
languages?: string[],
|
|
74
|
+
): OCRResult[];
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**参数:**
|
|
78
|
+
|
|
79
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
80
|
+
| ----------- | -------- | -------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
|
|
81
|
+
| `input` | string | 是 | - | 输入源,支持以下类型:<br>- `"screen"` - 当前屏幕截图<br>- `string` - 图片文件路径或 URL<br>- `imageId` - 图片 ID(通过 image 模块获取) |
|
|
82
|
+
| `x` | number | 否 | - | 识别区域左上角 x 坐标 |
|
|
83
|
+
| `y` | number | 否 | - | 识别区域左上角 y 坐标 |
|
|
84
|
+
| `ex` | number | 否 | - | 识别区域右下角 x 坐标 |
|
|
85
|
+
| `ey` | number | 否 | - | 识别区域右下角 y 坐标 |
|
|
86
|
+
| `languages` | string[] | 否 | ["zh-Hans", "en-US"] | 可选,指定识别语言列表,如 ["zh-Hans", "en-US"] |
|
|
87
|
+
|
|
88
|
+
**返回值:**
|
|
89
|
+
|
|
90
|
+
| 类型 | 描述 |
|
|
91
|
+
| ----------- | ---------------------- |
|
|
92
|
+
| OCRResult[] | 匹配的文本识别结果数组 |
|
|
93
|
+
|
|
94
|
+
**使用示例:**
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
// 识别整个屏幕
|
|
98
|
+
const fullScreenResults = appleOcr.recognize("screen", 0, 0, 0, 0);
|
|
99
|
+
logi(`识别到 ${fullScreenResults.length} 个文本区域`);
|
|
100
|
+
fullScreenResults.forEach((result, index) => {
|
|
101
|
+
logi(`文本 ${index + 1}: ${result.text} (置信度: ${result.confidence})`);
|
|
102
|
+
logi(`位置: (${result.x}, ${result.y}) - (${result.ex}, ${result.ey})`);
|
|
103
|
+
logi(`中心点: (${result.centerX}, ${result.centerY})`);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 识别屏幕指定区域
|
|
107
|
+
const regionResults = appleOcr.recognize("screen", 100, 100, 500, 300);
|
|
108
|
+
logi(`指定区域识别结果: ${JSON.stringify(regionResults)}`);
|
|
109
|
+
|
|
110
|
+
// 识别图片文件
|
|
111
|
+
const imageResults = appleOcr.recognize("/path/to/image.png", 0, 0, 800, 600);
|
|
112
|
+
if (imageResults.length > 0) {
|
|
113
|
+
logi("图片文字识别成功");
|
|
114
|
+
imageResults.forEach((result) => {
|
|
115
|
+
logi(`识别文字: ${result.text}`);
|
|
116
|
+
logi(`区域: ${result.width}x${result.height}`);
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
logi("图片中未识别到文字");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 指定识别语言
|
|
123
|
+
const chineseResults = appleOcr.recognize("screen", 0, 0, 1920, 1080, [
|
|
124
|
+
"zh-Hans",
|
|
125
|
+
"en-US",
|
|
126
|
+
]);
|
|
127
|
+
logi(`中英文识别结果: ${JSON.stringify(chineseResults)}`);
|
|
128
|
+
|
|
129
|
+
// 识别当前屏幕
|
|
130
|
+
const screenResults = appleOcr.recognize("screen", 0, 0, 1920, 1080);
|
|
131
|
+
logi(`屏幕识别结果: ${JSON.stringify(screenResults)}`);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 数字识别
|
|
135
|
+
|
|
136
|
+
#### recognizeNumbers
|
|
137
|
+
|
|
138
|
+
执行专门的数字 OCR 识别,针对数字识别进行了优化,提高数字识别的准确性。
|
|
139
|
+
|
|
140
|
+
**支持字符**: 0-9 数字、逗号(,)、小数点(.)、加号(+)、减号(-)
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
function recognizeNumbers(
|
|
144
|
+
input: string,
|
|
145
|
+
x?: number,
|
|
146
|
+
y?: number,
|
|
147
|
+
ex?: number,
|
|
148
|
+
ey?: number,
|
|
149
|
+
): OCRResult[];
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**参数:**
|
|
153
|
+
|
|
154
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
155
|
+
| ------- | ------ | -------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
156
|
+
| `input` | string | 是 | - | 输入源,支持以下类型: <br>-`"screen"` 当前屏幕截图 <br>- `string` 图片文件路径或 URL <br>- `imageId` 图片 ID(通过 image 模块获取) |
|
|
157
|
+
| `x` | number | 否 | - | 识别区域左上角 x 坐标 |
|
|
158
|
+
| `y` | number | 否 | - | 识别区域左上角 y 坐标 |
|
|
159
|
+
| `ex` | number | 否 | - | 识别区域右下角 x 坐标 |
|
|
160
|
+
| `ey` | number | 否 | - | 识别区域右下角 y 坐标 |
|
|
161
|
+
|
|
162
|
+
**返回值:**
|
|
163
|
+
|
|
164
|
+
| 类型 | 描述 |
|
|
165
|
+
| ------------- | ---------------------- |
|
|
166
|
+
| `OCRResult[]` | 匹配的数字识别结果数组 |
|
|
167
|
+
|
|
168
|
+
**使用示例:**
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
// 识别屏幕中的数字
|
|
172
|
+
const numberResults = appleOcr.recognizeNumbers("screen", 100, 100, 500, 300);
|
|
173
|
+
logi(`识别到 ${numberResults.length} 个数字区域`);
|
|
174
|
+
|
|
175
|
+
numberResults.forEach((result, index) => {
|
|
176
|
+
logi(`数字 ${index + 1}: ${result.text}`);
|
|
177
|
+
logi(`置信度: ${result.confidence}`);
|
|
178
|
+
logi(`位置: (${result.centerX}, ${result.centerY})`);
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 文本查找
|
|
183
|
+
|
|
184
|
+
#### findText
|
|
185
|
+
|
|
186
|
+
执行指定文本查找,在识别结果中查找特定的文本内容。使用全字匹配模式,确保精确匹配目标文本。
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
function findText(
|
|
190
|
+
input: string,
|
|
191
|
+
texts: string[],
|
|
192
|
+
x?: number,
|
|
193
|
+
y?: number,
|
|
194
|
+
ex?: number,
|
|
195
|
+
ey?: number,
|
|
196
|
+
languages?: string[],
|
|
197
|
+
): OCRResult[];
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**参数:**
|
|
201
|
+
|
|
202
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
203
|
+
| ----------- | -------- | -------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
|
|
204
|
+
| `input` | string | 是 | - | 输入源,支持以下类型: <br>-`"screen"` 当前屏幕截图 <br>- `string` 图片文件路径或 URL <br>- `imageId` 图片 ID(通过 image 模块获取) |
|
|
205
|
+
| `texts` | string[] | 是 | - | 要查找的文本数组 |
|
|
206
|
+
| `x` | number | 否 | - | 识别区域左上角 x 坐标 |
|
|
207
|
+
| `y` | number | 否 | - | 识别区域左上角 y 坐标 |
|
|
208
|
+
| `ex` | number | 否 | - | 识别区域右下角 x 坐标 |
|
|
209
|
+
| `ey` | number | 否 | - | 识别区域右下角 y 坐标 |
|
|
210
|
+
| `languages` | string[] | 否 | ["zh-Hans", "en-US"] | 可选,指定识别语言列表,如 ["zh-Hans", "en-US"] |
|
|
211
|
+
|
|
212
|
+
**返回值:**
|
|
213
|
+
|
|
214
|
+
| 类型 | 描述 |
|
|
215
|
+
| ------------- | ---------------------- |
|
|
216
|
+
| `OCRResult[]` | 匹配的文本识别结果数组 |
|
|
217
|
+
|
|
218
|
+
**使用示例:**
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
// 识别屏幕中的文本
|
|
222
|
+
const textResults = appleOcr.findText("screen", ["123", "456"], 0, 0, 100, 100);
|
|
223
|
+
logi(`识别到 ${textResults.length} 个文本区域`);
|
|
224
|
+
textResults.forEach((result, index) => {
|
|
225
|
+
logi(`文本 ${index + 1}: ${result.text} (置信度: ${result.confidence})`);
|
|
226
|
+
logi(`位置: (${result.x}, ${result.y}) - (${result.ex}, ${result.ey})`);
|
|
227
|
+
logi(`中心点: (${result.centerX}, ${result.centerY})`);
|
|
228
|
+
});
|
|
229
|
+
```
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# 配置模块 (Config)
|
|
2
|
+
|
|
3
|
+
配置模块提供了读取、更新和删除应用配置的功能。
|
|
4
|
+
|
|
5
|
+
网页的 ms.setConfig 对应 config.set
|
|
6
|
+
|
|
7
|
+
网页的 ms.getConfig 对应 config.get
|
|
8
|
+
|
|
9
|
+
网页的 ms.getAllConfig 对应 config.all
|
|
10
|
+
|
|
11
|
+
网页的 ms.removeConfig 对应 config.remove
|
|
12
|
+
|
|
13
|
+
## API 参考
|
|
14
|
+
|
|
15
|
+
### 配置读取
|
|
16
|
+
|
|
17
|
+
#### get - 读取配置项的值。
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
function get(key: string): any | null;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**参数:**
|
|
24
|
+
|
|
25
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
26
|
+
| ------ | ------ | -------- | ------ | -------- |
|
|
27
|
+
| `key` | string | 是 | - | 配置键名 |
|
|
28
|
+
|
|
29
|
+
**返回值:**
|
|
30
|
+
|
|
31
|
+
| 类型 | 描述 |
|
|
32
|
+
| ------------- | ------ |
|
|
33
|
+
| `any \| null` | 配置值 |
|
|
34
|
+
|
|
35
|
+
**示例:**
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
const maxRetries = config.get("maxRetries");
|
|
39
|
+
if (maxRetries !== null) {
|
|
40
|
+
logi(`最大重试次数: ${maxRetries}`);
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 配置管理
|
|
45
|
+
|
|
46
|
+
#### all - 获取所有配置的 JSON 格式数据。
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
function all(): Record<string, any>;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**返回值:**
|
|
53
|
+
|
|
54
|
+
| 类型 | 描述 |
|
|
55
|
+
| --------------------- | ------------------ |
|
|
56
|
+
| `Record<string, any>` | 包含所有配置的对象 |
|
|
57
|
+
|
|
58
|
+
**示例:**
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
const allConfigs = config.all();
|
|
62
|
+
logi(`所有配置: ${JSON.stringify(allConfigs, null, 2)}`);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### set - 更新或设置配置项的值。
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
function set(key: string, value: any): boolean;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**参数:**
|
|
72
|
+
|
|
73
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
74
|
+
| ------- | ------ | -------- | ------ | ---------- |
|
|
75
|
+
| `key` | string | 是 | - | 配置键名 |
|
|
76
|
+
| `value` | any | 是 | - | 新的配置值 |
|
|
77
|
+
|
|
78
|
+
**返回值:**
|
|
79
|
+
|
|
80
|
+
| 类型 | 描述 |
|
|
81
|
+
| --------- | ------------ |
|
|
82
|
+
| `boolean` | 更新是否成功 |
|
|
83
|
+
|
|
84
|
+
**示例:**
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
// 更新不同类型的配置
|
|
88
|
+
const success1 = config.set("maxRetries", 5);
|
|
89
|
+
const success2 = config.set("apiBaseUrl", "https://api.example.com");
|
|
90
|
+
const success3 = config.set("debugEnabled", true);
|
|
91
|
+
|
|
92
|
+
if (success1 && success2 && success3) {
|
|
93
|
+
logi("配置更新成功");
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
#### remove - 删除指定的配置项。
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
function remove(key: string): boolean;
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**参数:**
|
|
104
|
+
|
|
105
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
106
|
+
| ------ | ------ | -------- | ------ | ---------------- |
|
|
107
|
+
| `key` | string | 是 | - | 要删除的配置键名 |
|
|
108
|
+
|
|
109
|
+
**返回值:**
|
|
110
|
+
|
|
111
|
+
| 类型 | 描述 |
|
|
112
|
+
| --------- | ------------ |
|
|
113
|
+
| `boolean` | 删除是否成功 |
|
|
114
|
+
|
|
115
|
+
**示例:**
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
const deleted = config.remove("temporaryConfig");
|
|
119
|
+
if (deleted) {
|
|
120
|
+
logi("临时配置已删除");
|
|
121
|
+
}
|
|
122
|
+
```
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# 加密模块 (CryptoUtils)
|
|
2
|
+
|
|
3
|
+
加密模块提供了常用的加密和解密功能,支持 AES、RSA 以及 MD5、SHA1、SHA256 等哈希算法。
|
|
4
|
+
|
|
5
|
+
## 功能概览
|
|
6
|
+
|
|
7
|
+
- **AES 加解密**: 支持 AES-ECB 模式的加密与解密
|
|
8
|
+
- **RSA 加解密**: 支持 RSA 公钥加密与私钥解密
|
|
9
|
+
- **哈希算法**: 支持 MD5, SHA1, SHA256 消息摘要计算
|
|
10
|
+
|
|
11
|
+
## API 参考
|
|
12
|
+
|
|
13
|
+
### AES 加解密
|
|
14
|
+
|
|
15
|
+
#### encryptWithAES_ECB - 使用 AES ECB 模式加密数据
|
|
16
|
+
|
|
17
|
+
默认使用 PKCS7 填充。
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
function encryptWithAES_ECB(
|
|
21
|
+
data: string,
|
|
22
|
+
aesKey: string,
|
|
23
|
+
noPadding?: boolean
|
|
24
|
+
): string;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**参数:**
|
|
28
|
+
|
|
29
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
30
|
+
| ----------- | ------- | -------- | ------ | ---------------------------------------------------------------------- |
|
|
31
|
+
| `data` | string | 是 | | 要加密的数据 |
|
|
32
|
+
| `aesKey` | string | 是 | | AES 密钥,支持 16 位、24 位、32 位字符串 |
|
|
33
|
+
| `noPadding` | boolean | 否 | false | 是否禁用填充。`false`: 使用 PKCS7 填充; `true`: 不使用填充 (NoPadding) |
|
|
34
|
+
|
|
35
|
+
**返回值:**
|
|
36
|
+
|
|
37
|
+
| 类型 | 描述 |
|
|
38
|
+
| -------- | -------------------------------- |
|
|
39
|
+
| `string` | 加密后的数据 (Base64 编码字符串) |
|
|
40
|
+
|
|
41
|
+
**示例:**
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
const data = "Hello World";
|
|
45
|
+
const key = "1234567890123456"; // 16位密钥
|
|
46
|
+
const encrypted = cryptoUtils.encryptWithAES_ECB(data, key);
|
|
47
|
+
logi(`AES Encrypted: ${encrypted}`);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### decryptWithAES_ECB - 使用 AES ECB 模式解密数据
|
|
51
|
+
|
|
52
|
+
默认使用 PKCS7 填充。
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
function decryptWithAES_ECB(
|
|
56
|
+
data: string,
|
|
57
|
+
aesKey: string,
|
|
58
|
+
noPadding?: boolean
|
|
59
|
+
): string;
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**参数:**
|
|
63
|
+
|
|
64
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
65
|
+
| ----------- | ------- | -------- | ------ | ---------------------------------------------------------------------- |
|
|
66
|
+
| `data` | string | 是 | | 要解密的数据 (Base64 编码字符串) |
|
|
67
|
+
| `aesKey` | string | 是 | | AES 密钥,支持 16 位、24 位、32 位字符串 |
|
|
68
|
+
| `noPadding` | boolean | 否 | false | 是否禁用填充。`false`: 使用 PKCS7 填充; `true`: 不使用填充 (NoPadding) |
|
|
69
|
+
|
|
70
|
+
**返回值:**
|
|
71
|
+
|
|
72
|
+
| 类型 | 描述 |
|
|
73
|
+
| -------- | ---------------- |
|
|
74
|
+
| `string` | 解密后的原始数据 |
|
|
75
|
+
|
|
76
|
+
**示例:**
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
const encryptedData = "Base64EncodedString...";
|
|
80
|
+
const key = "1234567890123456";
|
|
81
|
+
const decrypted = cryptoUtils.decryptWithAES_ECB(encryptedData, key);
|
|
82
|
+
logi(`AES Decrypted: ${decrypted}`);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### RSA 加解密
|
|
86
|
+
|
|
87
|
+
#### encryptWithRSA - 使用 RSA 公钥加密数据
|
|
88
|
+
|
|
89
|
+
使用 PKCS1 填充。
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
function encryptWithRSA(data: string, rsaPublicKey: string): string;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**参数:**
|
|
96
|
+
|
|
97
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
98
|
+
| -------------- | ------ | -------- | ------ | ------------ |
|
|
99
|
+
| `data` | string | 是 | | 要加密的数据 |
|
|
100
|
+
| `rsaPublicKey` | string | 是 | | RSA 公钥 |
|
|
101
|
+
|
|
102
|
+
**返回值:**
|
|
103
|
+
|
|
104
|
+
| 类型 | 描述 |
|
|
105
|
+
| -------- | -------------------------------- |
|
|
106
|
+
| `string` | 加密后的数据 (Base64 编码字符串) |
|
|
107
|
+
|
|
108
|
+
**示例:**
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
const data = "123456";
|
|
112
|
+
const publicKey = `-----BEGIN PUBLIC KEY-----
|
|
113
|
+
公钥内容
|
|
114
|
+
-----END PUBLIC KEY-----
|
|
115
|
+
`;
|
|
116
|
+
const encrypted = cryptoUtils.encryptWithRSA(data, publicKey);
|
|
117
|
+
logi(`RSA Encrypted: ${encrypted}`);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### decryptWithRSA - 使用 RSA 私钥解密数据
|
|
121
|
+
|
|
122
|
+
使用 PKCS1 填充。
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
function decryptWithRSA(data: string, rsaPrivateKey: string): string;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**参数:**
|
|
129
|
+
|
|
130
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
131
|
+
| --------------- | ------ | -------- | ------ | -------------------------------- |
|
|
132
|
+
| `data` | string | 是 | | 要解密的数据 (Base64 编码字符串) |
|
|
133
|
+
| `rsaPrivateKey` | string | 是 | | RSA 私钥 |
|
|
134
|
+
|
|
135
|
+
**返回值:**
|
|
136
|
+
|
|
137
|
+
| 类型 | 描述 |
|
|
138
|
+
| -------- | ---------------- |
|
|
139
|
+
| `string` | 解密后的原始数据 |
|
|
140
|
+
|
|
141
|
+
**示例:**
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
const encryptedData = "加密后字符串";
|
|
145
|
+
const privateKey = `-----BEGIN PRIVATE KEY-----
|
|
146
|
+
私钥内容
|
|
147
|
+
-----END PRIVATE KEY-----`;
|
|
148
|
+
const decrypted = cryptoUtils.decryptWithRSA(encryptedData, privateKey);
|
|
149
|
+
logi(`RSA Decrypted: ${decrypted}`);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 哈希算法
|
|
153
|
+
|
|
154
|
+
#### md5 - 计算 MD5 值
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
function md5(data: string): string;
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**参数:**
|
|
161
|
+
|
|
162
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
163
|
+
| ------ | ------ | -------- | ------ | ----------------- |
|
|
164
|
+
| `data` | string | 是 | | 要计算 MD5 的数据 |
|
|
165
|
+
|
|
166
|
+
**返回值:**
|
|
167
|
+
|
|
168
|
+
| 类型 | 描述 |
|
|
169
|
+
| -------- | ------------------------------- |
|
|
170
|
+
| `string` | MD5 哈希值 (小写 16 进制字符串) |
|
|
171
|
+
|
|
172
|
+
**示例:**
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
const data = "123456";
|
|
176
|
+
const hash = cryptoUtils.md5(data);
|
|
177
|
+
logi(`MD5: ${hash}`); // e10adc3949ba59abbe56e057f20f883e
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### sha1 - 计算 SHA1 值
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
function sha1(data: string, key?: string): string;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**参数:**
|
|
187
|
+
|
|
188
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
189
|
+
| ------ | ------ | -------- | ------ | -------------------------- |
|
|
190
|
+
| `data` | string | 是 | | 要计算 SHA1 的数据 |
|
|
191
|
+
| `key` | string | 否 | | 可选的密钥,用于 HMAC-SHA1 |
|
|
192
|
+
|
|
193
|
+
**返回值:**
|
|
194
|
+
|
|
195
|
+
| 类型 | 描述 |
|
|
196
|
+
| -------- | -------------------------------- |
|
|
197
|
+
| `string` | SHA1 哈希值 (小写 16 进制字符串) |
|
|
198
|
+
|
|
199
|
+
**示例:**
|
|
200
|
+
|
|
201
|
+
```javascript
|
|
202
|
+
const data = "123456";
|
|
203
|
+
const hash = cryptoUtils.sha1(data);
|
|
204
|
+
logi(`SHA1: ${hash}`);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### sha256 - 计算 SHA256 值
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
function sha256(data: string, key?: string): string;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
**参数:**
|
|
214
|
+
|
|
215
|
+
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|
|
216
|
+
| ------ | ------ | -------- | ------ | ---------------------------- |
|
|
217
|
+
| `data` | string | 是 | | 要计算 SHA256 的数据 |
|
|
218
|
+
| `key` | string | 否 | | 可选的密钥,用于 HMAC-SHA256 |
|
|
219
|
+
|
|
220
|
+
**返回值:**
|
|
221
|
+
|
|
222
|
+
| 类型 | 描述 |
|
|
223
|
+
| -------- | ---------------------------------- |
|
|
224
|
+
| `string` | SHA256 哈希值 (小写 16 进制字符串) |
|
|
225
|
+
|
|
226
|
+
**示例:**
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
const data = "123456";
|
|
230
|
+
const hash = cryptoUtils.sha256(data);
|
|
231
|
+
logi(`SHA256: ${hash}`);
|
|
232
|
+
```
|