github panva/jose v4.2.0

latest releases: v5.9.3, v5.9.2, v5.9.1...
2 years ago

Features

example Usage

import * as jose from "jose";

const firstRecipientKeyPair = await jose.generateKeyPair("RSA-OAEP-256");
const secondRecipientKeyPair = await jose.generateKeyPair("ECDH-ES+A256KW");
const thirdRecipientSecret = await jose.generateSecret("A256GCMKW");

const encoder = new TextEncoder();
const plaintext = encoder.encode(
  "It’s a dangerous business, Frodo, going out your door."
);
const additionalAuthenticatedData = encoder.encode(
  "The Fellowship of the Ring"
);

const enc = new jose.GeneralEncrypt(plaintext)
  .setAdditionalAuthenticatedData(additionalAuthenticatedData)
  .setProtectedHeader({ enc: "A256GCM" });

enc
  .addRecipient(firstRecipientKeyPair.publicKey)
  .setUnprotectedHeader({ alg: "RSA-OAEP-256" });
enc
  .addRecipient(secondRecipientKeyPair.publicKey)
  .setUnprotectedHeader({ alg: "ECDH-ES+A256KW" });
enc
  .addRecipient(thirdRecipientSecret)
  .setUnprotectedHeader({ alg: "A256GCMKW" });

const jwe = await enc.encrypt();

console.log(JSON.stringify(jwe, null, 4));

for (const recipientKey of [
  firstRecipientKeyPair.privateKey,
  secondRecipientKeyPair.privateKey,
  thirdRecipientSecret,
]) {
  await jose.generalDecrypt(jwe, recipientKey);
}

Don't miss a new jose release

NewReleases is sending notifications on new releases.