Skip to content

Instantly share code, notes, and snippets.

@cardoso
Last active October 17, 2022 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cardoso/84f09d67f7bf0d79b8c013461fa7412f to your computer and use it in GitHub Desktop.
Save cardoso/84f09d67f7bf0d79b8c013461fa7412f to your computer and use it in GitHub Desktop.
export default async (publicKeyJwk, privateKeyJwk) => {
const publicKey = await window.crypto.subtle.importKey(
"jwk",
publicKeyJwk,
{
name: "ECDH",
namedCurve: "P-256",
},
true,
[]
);
const privateKey = await window.crypto.subtle.importKey(
"jwk",
privateKeyJwk,
{
name: "ECDH",
namedCurve: "P-256",
},
true,
["deriveKey", "deriveBits"]
);
return await window.crypto.subtle.deriveKey(
{ name: "ECDH", public: publicKey },
privateKey,
{ name: "AES-GCM", length: 256 },
true,
["encrypt", "decrypt"]
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment