CryptoKeyPair

The CryptoKeyPair dictionary of the Web Crypto API represents a key pair for an asymmetric cryptography algorithm, also known as a public-key algorithm.

A CryptoKeyPair object can be obtained using SubtleCrypto.generateKey(), when the selected algorithm is one of the asymmetric algorithms: RSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, ECDSA, or ECDH.

It contains two properties, which are both CryptoKey objects: a privateKey property containing the private key and a publicKey property containing the public key.

Properties

CryptoKey.privateKey
A CryptoKey object representing the private key. For encryption and decryption algorithms, this key is used to decrypt. For signing and verification algorithms it is used to sign.
CryptoKey.publicKey
A CryptoKey object representing the public key. For encryption and decryption algorithms, this key is used to encrypt. For signing and verification algorithms it is used to verify signatures.

Examples

The examples for SubtleCrypto methods often use CryptoKeyPair objects. For example:

Specifications

Specification Status Comment
Web Cryptography API
The definition of 'CryptoKeyPair' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
CryptoKeyPairChrome Full support 37Edge Full support YesFirefox Full support 34IE No support NoOpera ? Safari No support NoWebView Android Full support 37Chrome Android Full support 37Firefox Android Full support 34Opera Android ? Safari iOS No support NoSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Contributors to this page: mdnwebdocs-bot, wbamberg, chrisdavidmills
Last updated by: mdnwebdocs-bot,