aesgcmkw.js 688 B

1234567891011121314
  1. import encrypt from '../runtime/encrypt.js';
  2. import decrypt from '../runtime/decrypt.js';
  3. import generateIv from './iv.js';
  4. import { encode as base64url } from '../runtime/base64url.js';
  5. export async function wrap(alg, key, cek, iv) {
  6. const jweAlgorithm = alg.slice(0, 7);
  7. iv || (iv = generateIv(jweAlgorithm));
  8. const { ciphertext: encryptedKey, tag } = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array(0));
  9. return { encryptedKey, iv: base64url(iv), tag: base64url(tag) };
  10. }
  11. export async function unwrap(alg, key, encryptedKey, iv, tag) {
  12. const jweAlgorithm = alg.slice(0, 7);
  13. return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
  14. }