Expand description
Code related to ECDSA
Functions
sourceexportKey
exportKey
source(format: KeyFormat, key: EcdsaPubCryptoKey | EcdsaPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
(format: KeyFormat, key: EcdsaPubCryptoKey | EcdsaPrivCryptoKey): Promise<ArrayBuffer | JsonWebKey>
Export an ECDSA public or private key
example
const pubKeyJwk = await ECDSA.exportKey("jwk", keyPair.publicKey.self);
example
const privKeyJwk = await ECDSA.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: EcdsaPubCryptoKey | EcdsaPrivCryptoKey
Returns Promise<ArrayBuffer | JsonWebKey>
sourcegenerateKey
generateKey
source(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedCryptoKeyPair>
Generate a new ECDSA keypair
example
const keyPair = await ECDSA.generateKey();
example
const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDSA.generateKey({ namedCurve: "P-256" }, true, ['sign', 'verify']);
Parameters
algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<EcdsaProxiedCryptoKeyPair>
sourcegenerateKeyPair
generateKeyPair
source(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedCryptoKeyPair>
(algorithm?: Omit<EnforcedEcKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedCryptoKeyPair>
Generate a new ECDSA keypair
alias
generateKey
example
const keyPair = await ECDSA.generateKeyPair();
example
const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, false);
example
const keyPair = await ECDSA.generateKeyPair({ namedCurve: "P-256" }, true, ['sign', 'verify']);
Parameters
algorithm: Omit<EnforcedEcKeyGenParams, "name"> = { namedCurve: Alg.Curve.P_521, }
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<EcdsaProxiedCryptoKeyPair>
sourceimportKey
importKey
source(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm?: Omit<EnforcedEcKeyImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedPubCryptoKey | EcdsaProxiedPrivCryptoKey>
(format: KeyFormat, key: BufferSource | JsonWebKey, algorithm?: Omit<EnforcedEcKeyImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]): Promise<EcdsaProxiedPubCryptoKey | EcdsaProxiedPrivCryptoKey>
Import an ECDSA public or private key
example
const pubKey = await ECDSA.importKey("jwk", pubKeyJwk, { namedCurve: "P-521" }, true, ['verify']);
example
const privKey = await ECDSA.importKey("jwk", privKeyJwk, { namedCurve: "P-521" }, true, ['sign']);
Parameters
format: KeyFormat
key: BufferSource | JsonWebKey
algorithm: Omit<EnforcedEcKeyImportParams, "name"> = { namedCurve: Alg.Curve.P_521, }
Optional extractable: boolean
Optional keyUsages: KeyUsage[]
Returns Promise<EcdsaProxiedPubCryptoKey | EcdsaProxiedPrivCryptoKey>
sourcesign
sign
source(algorithm: Omit<EnforcedEcdsaParams, "name">, key: EcdsaPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
(algorithm: Omit<EnforcedEcdsaParams, "name">, key: EcdsaPrivCryptoKey, data: BufferSource): Promise<ArrayBuffer>
Sign a given payload
example
const message = new TextEncoder().encode("a message");
const signature = await ECDSA.sign({hash: "SHA-512"}, keyPair.privateKey.self, message);
example
const message = new TextEncoder().encode("a message");
const signature = await keyPair.privateKey.sign({hash: "SHA-512"}, message);
Parameters
algorithm: Omit<EnforcedEcdsaParams, "name">
key: EcdsaPrivCryptoKey
data: BufferSource
Returns Promise<ArrayBuffer>
sourceverify
verify
source(algorithm: Omit<EnforcedEcdsaParams, "name">, key: EcdsaPubCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
(algorithm: Omit<EnforcedEcdsaParams, "name">, key: EcdsaPubCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>
Verify a given signature
example
const message = new TextEncoder().encode("a message");
const isVerified = await ECDSA.verify({hash: "SHA-512"}, keyPair.publicKey.self, signature, message);
example
const message = new TextEncoder().encode("a message");
const isVerified = await keyPair.publicKey.verify({hash: "SHA-512"}, signature, message);
Parameters
algorithm: Omit<EnforcedEcdsaParams, "name">
key: EcdsaPubCryptoKey
signature: BufferSource
data: BufferSource