@buka/nestjs-kit 4.9.0 → 4.9.1

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.mjs CHANGED
@@ -8258,14 +8258,17 @@ let EnvelopeEncryptionV1Cipher = _EnvelopeEncryptionV1Cipher = class EnvelopeEnc
8258
8258
  }
8259
8259
  async decrypt(cmd) {
8260
8260
  if (cmd.payload.cipherVersion !== this.version) throw new Error(`Cipher version mismatch: expected ${this.version}, got ${cmd.payload.cipherVersion}`);
8261
- const dek = await this.kmsProvider.decryptDek(cmd.envelope.kekId, cmd.envelope.kekVersion, cmd.envelope.dek);
8262
- const decipher = createDecipheriv(this.algorithm, dek, cmd.payload.cipherIv, { authTagLength: 16 });
8263
- const aad = this.buildAad(cmd.envelope.kekId, cmd.extraAad);
8264
- decipher.setAAD(aad);
8265
- decipher.setAuthTag(cmd.payload.cipherTag);
8266
- const decrypted = Buffer.concat([decipher.update(cmd.payload.ciphertext), decipher.final()]);
8267
- dek.fill(0);
8268
- return decrypted;
8261
+ const sharedDek = await this.kmsProvider.decryptDek(cmd.envelope.kekId, cmd.envelope.kekVersion, cmd.envelope.dek);
8262
+ const dek = Buffer.from(sharedDek);
8263
+ try {
8264
+ const decipher = createDecipheriv(this.algorithm, dek, cmd.payload.cipherIv, { authTagLength: 16 });
8265
+ const aad = this.buildAad(cmd.envelope.kekId, cmd.extraAad);
8266
+ decipher.setAAD(aad);
8267
+ decipher.setAuthTag(cmd.payload.cipherTag);
8268
+ return Buffer.concat([decipher.update(cmd.payload.ciphertext), decipher.final()]);
8269
+ } finally {
8270
+ dek.fill(0);
8271
+ }
8269
8272
  }
8270
8273
  };
8271
8274
  EnvelopeEncryptionV1Cipher = _EnvelopeEncryptionV1Cipher = __decorate([Injectable(), __decorateMetadata("design:paramtypes", [typeof (_ref$1 = typeof KmsProvider !== "undefined" && KmsProvider) === "function" ? _ref$1 : Object])], EnvelopeEncryptionV1Cipher);