aesgcmkw.js 600 B

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