aesgcmkw.js 935 B

12345678910111213141516171819
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.unwrap = exports.wrap = void 0;
  4. const encrypt_js_1 = require("../runtime/encrypt.js");
  5. const decrypt_js_1 = require("../runtime/decrypt.js");
  6. const iv_js_1 = require("./iv.js");
  7. const base64url_js_1 = require("../runtime/base64url.js");
  8. async function wrap(alg, key, cek, iv) {
  9. const jweAlgorithm = alg.slice(0, 7);
  10. iv || (iv = (0, iv_js_1.default)(jweAlgorithm));
  11. const { ciphertext: encryptedKey, tag } = await (0, encrypt_js_1.default)(jweAlgorithm, cek, key, iv, new Uint8Array(0));
  12. return { encryptedKey, iv: (0, base64url_js_1.encode)(iv), tag: (0, base64url_js_1.encode)(tag) };
  13. }
  14. exports.wrap = wrap;
  15. async function unwrap(alg, key, encryptedKey, iv, tag) {
  16. const jweAlgorithm = alg.slice(0, 7);
  17. return (0, decrypt_js_1.default)(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
  18. }
  19. exports.unwrap = unwrap;