github panva/jose v4.2.0

latest releases: v5.9.6, v5.9.5, v5.9.4...
3 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.