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
);

Parameters

Returns Promise<ArrayBuffer>

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
);

Parameters

Returns Promise<HmacCryptoKey | AesCryptoKeys>

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");

Parameters

Returns Promise<ArrayBuffer | JsonWebKey>

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']);

Parameters

  • algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdhProxiedCryptoKeyPair>

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']);

Parameters

  • algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdhProxiedCryptoKeyPair>

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']);

Parameters

  • format: KeyFormat
  • key: BufferSource | JsonWebKey
  • algorithm: Omit<EnforcedEcKeyImportParams, "name"> = { namedCurve: Alg.Curve.P_521, }
  • Optional extractable: boolean
  • Optional keyUsages: KeyUsage[]

Returns Promise<EcdhProxiedPubCryptoKey | EcdhProxiedPrivCryptoKey>