Expand description

Code related to ECDH

Functions

Derive a shared bits between two ECDH key pairs

example
const keyPair = await ECDH.generateKey();
const otherKeyPair = await ECDH.generateKey();
const bits = await ECDH.deriveBits(
{ public: otherKeyPair.publicKey.self },
keyPair.privateKey.self,
128
);
example
const keyPair = await ECDH.generateKey();
const otherKeyPair = await ECDH.generateKey();
const bits = await keyPair.privateKey.deriveBits(
{ public: otherKeyPair.publicKey.self },
128
);

Derive a shared key between two ECDH key pairs

example
const keyPair = await ECDH.generateKey();
const otherKeyPair = await ECDH.generateKey();
const hmacParams: params.EnforcedHmacKeyGenParams = {
name: Authentication.Alg.Code.HMAC,
hash: SHA.Alg.Variant.SHA_512,
length: 512,
};
let key = await ECDH.deriveKey(
{ public: otherKeyPair.publicKey.self },
keyPair.privateKey.self,
hmacParams
);
example
const keyPair = await ECDH.generateKey();
const otherKeyPair = await ECDH.generateKey();
const hmacParams: params.EnforcedHmacKeyGenParams = {
name: Authentication.Alg.Code.HMAC,
hash: SHA.Alg.Variant.SHA_512,
length: 512,
};
let key = await keyPair.privateKey.deriveKey(
{ public: otherKeyPair.publicKey.self },
hmacParams
);

Export an ECDH public or private key

example
const pubKeyJwk = await ECDH.exportKey("jwk", keyPair.publicKey.self);
example
const privKeyJwk = await ECDH.exportKey("jwk", keyPair.privateKey.self);
example
const pubKeyJwk = await keyPair.publicKey.exportKey("jwk");
example
const privKeyJwk = await keyPair.privateKey.exportKey("jwk");

Generate a new ECDH keypair

example
const keyPair = await ECDH.generateKey();
example
const keyPair = await ECDH.generateKey({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDH.generateKey({ namedCurve: "P-256" }, true, ['deriveKey', 'deriveBits']);

Generate a new ECDH keypair

alias

generateKey

example
const keyPair = await ECDH.generateKeyPair();
example
const keyPair = await ECDH.generateKeyPair({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDH.generateKeyPair({ namedCurve: "P-256" }, true, ['deriveKey', 'deriveBits']);

Import an ECDH public or private key

example
const pubKey = await ECDH.importKey("jwk", pubKeyJwk, { namedCurve: "P-521" }, true, []);
example
const privKey = await ECDH.importKey("jwk", privKeyJwk, { namedCurve: "P-521" }, true, ['deriveBits', 'deriveKey']);