encrypt.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CompactEncrypt = void 0;
  4. const encrypt_js_1 = require("../flattened/encrypt.js");
  5. class CompactEncrypt {
  6. constructor(plaintext) {
  7. this._flattened = new encrypt_js_1.FlattenedEncrypt(plaintext);
  8. }
  9. setContentEncryptionKey(cek) {
  10. this._flattened.setContentEncryptionKey(cek);
  11. return this;
  12. }
  13. setInitializationVector(iv) {
  14. this._flattened.setInitializationVector(iv);
  15. return this;
  16. }
  17. setProtectedHeader(protectedHeader) {
  18. this._flattened.setProtectedHeader(protectedHeader);
  19. return this;
  20. }
  21. setKeyManagementParameters(parameters) {
  22. this._flattened.setKeyManagementParameters(parameters);
  23. return this;
  24. }
  25. async encrypt(key, options) {
  26. const jwe = await this._flattened.encrypt(key, options);
  27. return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
  28. }
  29. }
  30. exports.CompactEncrypt = CompactEncrypt;