ccem 2.32.0 → 2.33.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/index.js +18 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -430,15 +430,28 @@ var decrypt = (text) => {
|
|
|
430
430
|
if (!text || !text.startsWith("enc:")) return text;
|
|
431
431
|
if (text.startsWith("enc:v2:")) {
|
|
432
432
|
const parts = text.split(":");
|
|
433
|
-
if (parts.length !== 5)
|
|
433
|
+
if (parts.length !== 5) {
|
|
434
|
+
throw new Error("Invalid enc:v2: ciphertext format");
|
|
435
|
+
}
|
|
436
|
+
const nonceHex = parts[2];
|
|
437
|
+
const ciphertextHex = parts[3];
|
|
438
|
+
const tagHex = parts[4];
|
|
439
|
+
if (!/^[0-9a-f]{24}$/i.test(nonceHex)) {
|
|
440
|
+
throw new Error("Invalid enc:v2: nonce");
|
|
441
|
+
}
|
|
442
|
+
if (!/^[0-9a-f]{32}$/i.test(tagHex)) {
|
|
443
|
+
throw new Error("Invalid enc:v2: auth tag");
|
|
444
|
+
}
|
|
445
|
+
if (ciphertextHex.length === 0 || !/^[0-9a-f]+$/i.test(ciphertextHex) || ciphertextHex.length % 2 !== 0) {
|
|
446
|
+
throw new Error("Invalid enc:v2: ciphertext");
|
|
447
|
+
}
|
|
434
448
|
try {
|
|
435
449
|
const key = getOrCreateInstallKey();
|
|
436
|
-
const nonce = Buffer.from(
|
|
437
|
-
const
|
|
438
|
-
const tag = Buffer.from(parts[4], "hex");
|
|
450
|
+
const nonce = Buffer.from(nonceHex, "hex");
|
|
451
|
+
const tag = Buffer.from(tagHex, "hex");
|
|
439
452
|
const decipher = crypto.createDecipheriv(V2_ALGORITHM, key, nonce);
|
|
440
453
|
decipher.setAuthTag(tag);
|
|
441
|
-
let decrypted = decipher.update(
|
|
454
|
+
let decrypted = decipher.update(ciphertextHex, "hex", "utf8");
|
|
442
455
|
decrypted += decipher.final("utf8");
|
|
443
456
|
return decrypted;
|
|
444
457
|
} catch {
|