Expand description
Code related to ECDH
Functions
sourcederiveBits
deriveBits
source(algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">, baseKey: EcdhPrivCryptoKey, length: number): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">, baseKey: EcdhPrivCryptoKey, length: number): Promise<ArrayBuffer>
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
algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">
baseKey: EcdhPrivCryptoKey
length: number
Returns Promise<ArrayBuffer>
sourcederiveKey
deriveKey
source(algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">, baseKey: EcdhPrivCryptoKey, derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacCryptoKey | AesCryptoKeys>
(algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">, baseKey: EcdhPrivCryptoKey, derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<HmacCryptoKey | AesCryptoKeys>
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
algorithm: Omit<EnforcedEcdhKeyDeriveParams, "name">
baseKey: EcdhPrivCryptoKey
derivedKeyType: EnforcedHmacKeyGenParams | EnforcedAesKeyGenParams
extractable: boolean = true
Optional keyUsages: KeyUsage[]
Returns Promise<HmacCryptoKey | AesCryptoKeys>
sourceexportKey
exportKey
source(format: KeyFormat, key: EcdhPubCryptoKey | EcdhPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: EcdhPubCryptoKey | EcdhPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
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
format: KeyFormat
key: EcdhPubCryptoKey | EcdhPrivCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdhProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdhProxiedCryptoKeyPair>
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>
sourcegenerateKeyPair
generateKeyPair
source(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdhProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): 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>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm?: Omit<EnforcedEcKeyImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdhProxiedPubCryptoKey | EcdhProxiedPrivCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm?: Omit<EnforcedEcKeyImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdhProxiedPubCryptoKey | EcdhProxiedPrivCryptoKey>
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[]