@diana-db/odm 1.6.0 → 1.7.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.
|
@@ -6,15 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.CryptoHelper = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const ALGORITHM = 'aes-256-gcm';
|
|
9
|
-
const KEY_LEN = 32;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const TAG_LEN = 16;
|
|
9
|
+
const KEY_LEN = 32; // AES-256
|
|
10
|
+
const IV_LEN = 12; // Recommended for GCM
|
|
11
|
+
const TAG_LEN = 16; // GCM auth tag
|
|
13
12
|
class CryptoHelper {
|
|
14
13
|
static encrypt(password, plaintext) {
|
|
15
|
-
const salt = crypto_1.default.randomBytes(SALT_LEN);
|
|
16
14
|
const iv = crypto_1.default.randomBytes(IV_LEN);
|
|
17
|
-
const key = crypto_1.default.
|
|
15
|
+
const key = crypto_1.default.createHash('sha256').update(password).digest().subarray(0, KEY_LEN);
|
|
18
16
|
const cipher = crypto_1.default.createCipheriv(ALGORITHM, key, iv);
|
|
19
17
|
const ciphertext = Buffer.concat([
|
|
20
18
|
cipher.update(plaintext),
|
|
@@ -22,7 +20,6 @@ class CryptoHelper {
|
|
|
22
20
|
]);
|
|
23
21
|
const tag = cipher.getAuthTag();
|
|
24
22
|
return Buffer.concat([
|
|
25
|
-
salt,
|
|
26
23
|
iv,
|
|
27
24
|
tag,
|
|
28
25
|
ciphertext,
|
|
@@ -30,11 +27,10 @@ class CryptoHelper {
|
|
|
30
27
|
}
|
|
31
28
|
static decrypt(password, text) {
|
|
32
29
|
const encrypted = Buffer.from(text, 'base64');
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const key = crypto_1.default.scryptSync(password, salt, KEY_LEN);
|
|
30
|
+
const iv = encrypted.subarray(0, IV_LEN);
|
|
31
|
+
const tag = encrypted.subarray(IV_LEN, IV_LEN + TAG_LEN);
|
|
32
|
+
const ciphertext = encrypted.subarray(IV_LEN + TAG_LEN);
|
|
33
|
+
const key = crypto_1.default.createHash('sha256').update(password).digest().subarray(0, KEY_LEN);
|
|
38
34
|
const decipher = crypto_1.default.createDecipheriv(ALGORITHM, key, iv);
|
|
39
35
|
decipher.setAuthTag(tag);
|
|
40
36
|
return Buffer.concat([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-helper.js","sourceRoot":"","sources":["../../src/helpers/crypto-helper.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"crypto-helper.js","sourceRoot":"","sources":["../../src/helpers/crypto-helper.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,MAAM,SAAS,GAAG,aAAa,CAAC;AAChC,MAAM,OAAO,GAAG,EAAE,CAAC,CAAC,UAAU;AAC9B,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,sBAAsB;AACzC,MAAM,OAAO,GAAG,EAAE,CAAC,CAAC,eAAe;AAEnC,MAAa,YAAY;IAChB,MAAM,CAAC,OAAO,CAAC,QAAgB,EAAE,SAAiB;QACvD,MAAM,EAAE,GAAG,gBAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,GAAG,GAAG,gBAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAEvF,MAAM,MAAM,GAAG,gBAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAEzD,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC;YAC/B,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACxB,MAAM,CAAC,KAAK,EAAE;SACf,CAAC,CA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