@king-3/file-kit 1.3.1 → 1.4.0
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/cli.js +24 -8
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,8 @@ import fs from "node:fs/promises";
|
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
7
|
import { accessSync, existsSync, mkdirSync } from "node:fs";
|
|
8
8
|
import { confirm, intro, isCancel, outro, password, select, spinner, text } from "@clack/prompts";
|
|
9
|
-
import { createCipheriv, createDecipheriv,
|
|
9
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
10
|
+
import { argon2id, hash } from "argon2";
|
|
10
11
|
import path$1 from "node:path/posix";
|
|
11
12
|
import ffmpegPath from "@ffmpeg-installer/ffmpeg";
|
|
12
13
|
import { execa } from "execa";
|
|
@@ -225,7 +226,7 @@ async function base64ToFile(archiveData, outputDir = ".") {
|
|
|
225
226
|
//#endregion
|
|
226
227
|
//#region src/config/defaults.ts
|
|
227
228
|
const CLI_NAME = "File Kit";
|
|
228
|
-
const CLI_VERSION = "1.
|
|
229
|
+
const CLI_VERSION = "1.4.0";
|
|
229
230
|
const CLI_ALIAS = "fkt";
|
|
230
231
|
/**
|
|
231
232
|
* 默认配置
|
|
@@ -459,9 +460,14 @@ var base64_default = defineCommand({
|
|
|
459
460
|
//#region src/config/crypto-algorithm.ts
|
|
460
461
|
const CRYPTO_ALGORITHM = {
|
|
461
462
|
name: "aes-256-gcm",
|
|
462
|
-
ivLength:
|
|
463
|
+
ivLength: 12,
|
|
463
464
|
saltLength: 32,
|
|
464
|
-
|
|
465
|
+
keyLength: 32,
|
|
466
|
+
argon2: {
|
|
467
|
+
memoryCost: 131072,
|
|
468
|
+
timeCost: 3,
|
|
469
|
+
parallelism: 4
|
|
470
|
+
}
|
|
465
471
|
};
|
|
466
472
|
|
|
467
473
|
//#endregion
|
|
@@ -469,8 +475,18 @@ const CRYPTO_ALGORITHM = {
|
|
|
469
475
|
/**
|
|
470
476
|
* 从密码派生密钥
|
|
471
477
|
*/
|
|
472
|
-
const deriveKey = (password$2, salt) => {
|
|
473
|
-
|
|
478
|
+
const deriveKey = async (password$2, salt) => {
|
|
479
|
+
const { argon2: argon2Config } = CRYPTO_ALGORITHM;
|
|
480
|
+
const result = await hash(password$2, {
|
|
481
|
+
type: argon2id,
|
|
482
|
+
salt,
|
|
483
|
+
memoryCost: argon2Config.memoryCost,
|
|
484
|
+
timeCost: argon2Config.timeCost,
|
|
485
|
+
parallelism: argon2Config.parallelism,
|
|
486
|
+
hashLength: CRYPTO_ALGORITHM.keyLength,
|
|
487
|
+
raw: true
|
|
488
|
+
});
|
|
489
|
+
return Buffer.from(result);
|
|
474
490
|
};
|
|
475
491
|
/**
|
|
476
492
|
* 加密文件
|
|
@@ -485,7 +501,7 @@ async function encrypt(filePath, outputPath, options) {
|
|
|
485
501
|
const fileExt = getFileExt(filePath);
|
|
486
502
|
const salt = randomBytes(CRYPTO_ALGORITHM.saltLength);
|
|
487
503
|
const iv = randomBytes(CRYPTO_ALGORITHM.ivLength);
|
|
488
|
-
const key = deriveKey(options.password, salt);
|
|
504
|
+
const key = await deriveKey(options.password, salt);
|
|
489
505
|
const cipher = createCipheriv(CRYPTO_ALGORITHM.name, key, iv);
|
|
490
506
|
const encrypted = Buffer.concat([cipher.update(fileBuffer), cipher.final()]);
|
|
491
507
|
const authTag = cipher.getAuthTag();
|
|
@@ -526,7 +542,7 @@ async function decrypt(archiveData, outputDir = ".", options) {
|
|
|
526
542
|
const iv = base64ToBuffer(file.iv);
|
|
527
543
|
const authTag = base64ToBuffer(file.authTag);
|
|
528
544
|
const encrypted = base64ToBuffer(file.encrypted);
|
|
529
|
-
const key = deriveKey(options.password, salt);
|
|
545
|
+
const key = await deriveKey(options.password, salt);
|
|
530
546
|
const decipher = createDecipheriv(CRYPTO_ALGORITHM.name, key, iv);
|
|
531
547
|
decipher.setAuthTag(authTag);
|
|
532
548
|
let decrypted;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@king-3/file-kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "多功能文件工具箱(Base64 转换 · 视频转音频 · 加密/解密)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@clack/prompts": "^0.11.0",
|
|
42
42
|
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
43
43
|
"ansis": "^4.2.0",
|
|
44
|
+
"argon2": "^0.44.0",
|
|
44
45
|
"citty": "^0.1.6",
|
|
45
46
|
"execa": "^9.6.1"
|
|
46
47
|
},
|