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
CryptoKeyPair.privateKey- A
CryptoKeyobject 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. CryptoKeyPair.publicKey- A
CryptoKeyobject 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:
SubtleCrypto.generateKey()SubtleCrypto.deriveKey()SubtleCrypto.importKey()SubtleCrypto.exportKey()SubtleCrypto.wrapKey()SubtleCrypto.unwrapKey()SubtleCrypto.encrypt()SubtleCrypto.decrypt()SubtleCrypto.sign()SubtleCrypto.verify()
Specifications
| Specification | Status | Comment |
| Web Cryptography APIThe definition of 'CryptoKeyPair' in that specification. | Recommendation | Initial definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
CryptoKeyPair
|
Chrome
Full support 37 |
Edge
Full support ≤18 |
Firefox
Full support 34 |
IE
No support No |
Opera
Full support 24 |
Safari
No support No |
WebView Android
Full support 37 |
Chrome Android
Full support 37 |
Firefox Android
Full support 34 |
Opera Android
Full support 24 |
Safari iOS
No support No |
Samsung Internet Android
Full support 3.0 |
Legend
- Full support
- Full support
- No support
- No support
See also
SubtleCrypto.generateKey.SubtleCrypto.signandSubtleCrypto.verify.SubtleCrypto.encryptandSubtleCrypto.decrypt.
CryptoKeyPair by Mozilla Contributors is licensed under CC-BY-SA 2.5.